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
提示
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
using namespace std;
int a[40];
void f()
{
int j,k=0;
for (int i = 11; i <= 10000000; i = i*10+1)
for (j = 1; j <= 9; j ++)
a[k ++] = i*j;
}
int main ()
{
int n,m,i,j,k;
f();
while (scanf("%d%d",&n,&m)!=EOF)
{
int x=-1,y=0;
for (i = 0; i < 54; i ++)
{
if (a[i] >= n*2&& x==-1 )
x = i;
if (a[i] <= m*2)
{
y = i;
}
}
int sum = 0;
for (i = x; i <= y; i ++)
{
for (j = n; j <= m; j ++)
{
if(a[i]-j <j)
break;
if (a[i]-j >= n && a[i]-j <= m && a[i]-j >= j){
sum ++;
}
}
}
printf("%d\n",sum);
}
return 0;
}