博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Owl Geeks
阅读量:4568 次
发布时间:2019-06-08

本文共 2208 字,大约阅读时间需要 7 分钟。

 

The owls have the following equation:

Y = a × x2 + b × x

With ab, and N given, they decide to put into a set the integer values of Y that are less than or equal to N and that are outputted from the equation from any positive integer x.

With that set of numbers, they come up with the problem of finding the winning digit among them.

The winning digit is a digit from 0 to 9 that will get the maximum number of points. How are points for a digit calculated you may ask? Well, be a bit more patient, I’m going to tell you now.

For each number in the set, if the digit was the most repeated digit or tied with other digits as the most repeated digit in the ith number of set S, then it would get one point from that ith number.

Can you tell the owls what the winning digit is?

Input

The first line of input is T – the number of test cases.

The first line of each test case is ab, and N (1 ≤ a, b, N ≤ 105).

Output

For each test case, print on a line the winning digit with the maximum number of points. If there is a tie, print the minimum digit among them. If the set is empty, print  - 1.

Example

input

Copy

21 2 5020 3 10

output

Copy

3-1

题意:输入a,b,n,n是a*x*x+b*x的最大范围,例如第一组,n可以为3,8,15,24,35,48,将3,8,1,5,2,4,3,5,4,8存起来(要是332存3),输出最小而且个数最多的数

 

#include
#include
#include
#include
using namespace std;int c[100],d[100];int main(){ int T,a,b,n,r; scanf("%d",&T); while(T--) { scanf("%d%d%d",&a,&b,&n); r=0; memset(c,0,sizeof(c)); memset(d,0,sizeof(d)); for(int i=1;a*i*i+b*i<=n;i++) r=i; if(r==0) { puts("-1"); continue; } for(int i=1;i<=r;i++) { int s=a*i*i+b*i,v=0; memset(c,0,sizeof(c)); while(s) { c[s%10]++; v=max(v,c[s%10]); s/=10; } for(int j=0;j<=9;j++) if(c[j]==v) d[j]++; } int u=0; for(int i=0;i<=9;i++) if(d[i]>d[u]) u=i; printf("%d\n",u); } return 0;}

转载于:https://www.cnblogs.com/zcy19990813/p/9702811.html

你可能感兴趣的文章
用WM_COPYDATA消息来实现两个进程之间传递数据
查看>>
第二节 变量 、 基本类型 、 运算符 、 表达式 、 数据 、 类型转换 、 常量
查看>>
时间 空间复杂度小结(斐波那契 二分查找举例)
查看>>
MultiDataTrigger
查看>>
Behavior
查看>>
JavaSE基础---异常
查看>>
Struts 真正的零配置(约定优于配置)
查看>>
Django搭配Celery进行异步/定时任务(一)初步搭建
查看>>
2018.03.01(数据结构练习)
查看>>
java基本数据类型范围
查看>>
嵌入式开发之NorFlash 和NandFlash
查看>>
s3c2440存储控制器详解
查看>>
点击文本选中checkbox
查看>>
PCL中点云数据格式之间的转化
查看>>
memcached: error while loading shared libraries: libevent-2.0.so.5: cannot o解决
查看>>
hdu_1019Least Common Multiple(最小公倍数)
查看>>
规则引擎集成接口(一)初始体验
查看>>
[POI2006] KRA-The Disks (贪心)
查看>>
从原则、方案、策略及难点阐述分库分表
查看>>
apache+tomcat负载均衡3种实现方式
查看>>