ZOJ 3622 Magic Number 打表找规律

时间:2021-08-20 12:42:36
A - Magic Number

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Appoint description:
 

Description

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 思路:首先我们得用数学方法推出 只要满足10^ans%a==0,就是magic数,ans指的是a这个数的位数
题解:找规律,然后人工打表……
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int a1[] = {,,,,,,,,,};
int a2[] = {,,,,,,,,,};
int a3[] = {,,,,,,,,};
int a4[] = {,,,,,,,};
int a5[] = {,,,,,,,}; int main()
{
int ans,n,m,i;
while(~scanf("%d%d",&n,&m))
{
ans = ;
if(n>m)
swap(n,m);
for(i = ;i<;i++)
if(n<=a1[i] && a1[i]<=m)
ans++;
for(i = ;i<;i++)
if(n<=a2[i] && a2[i]<=m)
ans++;
for(i = ;i<;i++)
if(n<=a3[i] && a3[i]<=m)
ans++;
for(i = ;i<;i++)
if(n<=a4[i] && a4[i]<=m)
ans++;
for(i = ;i<;i++)
if(n<=a5[i] && a5[i]<=m)
ans++;
printf("%d\n",ans);
} return ;
}