Repeat Number(数论)

Repeat Number

题目描述:

Definition: a+b = c, if all the digits of c are same ( c is more than ten),

then we call a and b are Repeat Number.

My question is How many Repeat Numbers in [x,y].

输入

There are several test cases.

Each test cases contains two integers x, y(1<=x<=y<=1,000,000) described above.

Proceed to the end of file.

输出

For each test output the number of couple of Repeat Number in one line.

样例输入

1 10

10 12

样例输出

5

2

提示:

If a equals b, we can call a, b are Repeat Numbers too, and a is the Repeat Numbers for itself.

题目大意:

     输入一个范围[x,y],判断在这个范围内能够找到多少组<a,b>使得a+b=c,

     c需要满足每一位上的数全都一样并且 c > 10。

解题思路:

    先根据题目中给定的范围,将范围内所有满足条件的c存入数组。

    然后根据输入的范围求出最小范围x+x和最大范围y+y,在该范围

    内找满足条件的组合。

AC代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 #include <math.h>
 5 #include <stdlib.h>
 6
 7 using namespace std;
 8
 9 int aa[50];
10 int f()   // 将满足情况的c值存入数组
11 {
12     int i,j,k=0;
13     for (i = 11; i < 1000000; i=i*10+1)
14         for (j = 1; j <= 9; j ++)
15             aa[k ++] = i*j;
16     aa[k] = 1111111;   // 不要忘记这个最大的哦(1111111  在这个最大的范围内 1000000+1000000)
17 }
18 int main ()
19 {
20     f();
21     int a,b,j,i;
22     while (scanf("%d%d",&a,&b)!=EOF)
23     {
24         int sum = 0;
25         for (i = 0; i < 47; i ++)
26         {
27             if (a*2 <= aa[i] && aa[i] <= b*2)  // 判断是否在[a+a,b+b]范围内
28                 sum += min(aa[i]/2-a+1,b-(aa[i]+1)/2+1);
29         }
30         printf("%d\n",sum);
31     }
32     return 0;
33 }
34
35 /*
36  sum += min(aa[i]/2-a+1,b-(aa[i]+1)/2+1);
37  关于以上代码的解释:
38
39  举一个简单的例子  假如输入的x,y为1 10
40  只有一个11在[2,20]范围内
41  想一想那些数能够组合成11
42  (1,10)(2,9)(3,8)(4,7)(5,6)这五个
43  以(5,6)这一组为分界
44  (1(2(3(4(5,6)7)8)9)10)
45
46  假如输入的x,y为3 10
47  也只有一个11在[6,20]范围内
48  满足条件的组合
49  (3,8)(4,7)(5,6)这五个
50  以(5,6)这一组为分界
51 (3(4(5,6)7)8)
52
53 所以,根据c/2 到x和y的距离就能判断出有多少组合(选择较小值)
54  */
时间: 2024-08-02 11:03:28

Repeat Number(数论)的相关文章

Repeat Number

Problem B: Repeat Number Time Limit: 1 Sec  Memory Limit: 32 MB Description Definition: a+b = c, if all the digits of c are same ( c is more than ten),then we call a and b are Repeat Number. My question is How many Repeat Numbers in [x,y]. Input Ther

HDU 4937 Lucky Number(数论)

HDU 4937 Lucky Number 题目链接 题意:给定一个数字,求它再x进制下,每位进制位上都只有3,4,5,6,求这样的x有多少种,如果无限种输出-1 思路:首先3 4 5 6特判掉是无限的,很容易想到就不证明了,然后就是枚举数字的最后一位3,4,5,6,然后进制数肯定来自这个数字的因子,因为剩下的数字肯定是a1x^1 + a2x^2 + a3x^3...这样的,这样只要在因子中找进制,去判断即可.找因子的方法用先分解再dfs找,直接试除会超时 代码: #include <cstdi

2014辽宁省赛 Repeat Number

问题 C: Repeat Number 时间限制: 1 Sec  内存限制: 128 MB 提交: 23  解决: 7 [cid=1073&pid=2&langmask=0">提交][状态][论坛] 题目描写叙述 Definition: a+b = c, if all the digits of c are same ( c is more than ten).then we call a and b are Repeat Number. My question is Ho

NYOJ 411 Friends number (数论--因子和)

链接:点击打开链接 题意: Friends number 时间限制:2000 ms  |  内存限制:65535 KB 难度:2 描述 Paula and Tai are couple. There are many stories between them. The day Paula left by airplane, Tai send one message to telephone 2200284, then, everything is changing- (The story in

[POJ3696]The Luckiest number(数论)

题目:http://poj.org/problem?id=3696 题意:给你一个数字L,你要求出一个数N,使得N是L的倍数,且N的每位数都必须是8,输出N的位数(如果不存在输出0) 分析: 首先我们假设N是x个8组成的 那么88888...888=kL 提个8出来:8*111..1111=kL ① 因为题目只要求x的值,所以要弄出关于x的方程 11...111可以写成(10^k-1)/9 于是①变成了8(10^x-1)=9kL ② 再来回顾下题目,②式中x和k是变量,且都属于正整数,要根据②式

bzoj3000 Big Number 数论,斯特林公式

Description 给你两个整数N和K,要求你输出N!的K进制的位数. Input 有多组输入数据,每组输入数据各一行,每行两个数——N,K Output 每行一个数为输出结果 Sample Input 2 52 1010 10100 200 Sample Output 11769对于100%的数据,有2≤N≤2^31, 2≤K≤200,数据组数T≤200. 题解 用Stirling公式求近似值 位数=logk(n!)+1 ≍ logk(sqrt(2πn)*(n/e)^n)+1 = logk

38、EST序列拼接流程

转载:http://fhqdddddd.blog.163.com/blog/static/18699154201241014835362/ http://blog.sina.com.cn/s/blog_4476400f0100iq0x.html EST----对EST序列进行冗余查找,利用CD_HIT软件聚类,快速批量去除冗余序列 est-trimer(去掉帽子和尾巴,去掉太短而不可信的) RepeatMaster(去掉转座子等重复) seqclean(去除载体,线粒体叶绿体等序列) CAP3(

Look-and-Say 数列

Look-and-See (边看边说) 数列具有好玩儿而神秘的特性,本文简要介绍它和它衍生出来的康威常数. 沿革 1977年7月1-13日,国际奥林匹克数学竞赛在前南斯拉夫首都贝尔格莱德举行,赛间,荷兰队非正式地给英国队出了个难题(其实类似脑筋急转弯),大致是这样的: 1 1, 11, 21, 1211, 111221 上述数列的下一项是什么呢? 英国队未予答复... 故事并没有结束,后来,在剑桥大学执教的著名数学家约翰·霍顿·康威( John·Horton·Conway)从他的学生那儿拿到了这

如何使用python timeit模块使用实践

其实平时使用测试应用运行时间的情况 细算一下还真的很少.很久没有做性能优化的工作,不管是cProfile还是timeit模块都已经生疏了很久没有使用,我在以前的文章里面有提到过cPfile的性能测试使用,但是一直没有使用过这个更轻量级的运行时间测量库进行过仔细实践总结,今天就来总结一下. 从最简单的例子开始,比如我们想测试一个列表推导式究竟要比正常写for快多少. import timeit foooo = """ sum = [] for i in range(1000):