[ZOJ 3622] Magic Number

时间:2023-03-08 20:25:31

Magic Number


Time Limit: 2 Seconds      Memory Limit: 32768 KB

A positive number y is called magic number if for every positive integer x it satisfies that put y to the right of x, which will form a new integer z, z mod y = 0.

Input

The input has multiple cases, each case contains two positve integers m, n(1 <= m <= n <= 2^31-1), proceed to the end of file.

Output

For each case, output the total number of magic numbers between m and n(m, n inclusively).

Sample Input

1 1
1 10

Sample Output

1
4 分析:
设y有k位数,则需要满足 (x*10^k+y)%y==0
--> (x*10^k%y+0)%y==0
--> x*10^k%y==0
--> 由于x是任意的,假设x为质数,则需要满足(10^k)%y==0
直接判断会超时,先打表。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
#define N 100010 int n,m;
int len;
int num[N]=
{,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
}; int main()
{
while(scanf("%d%d",&m,&n)!=EOF)
{
if(m>n) swap(m,n);
int cnt=;
for(int i=;i<;i++)
{
if(m<=num[i] && num[i]<=n) cnt++;
}
cout<<cnt<<endl;
}
return ;
}