[ZOJ 3622] Magic Number

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]=

{1,

2,

5,

10,

20,

25,

50,

100,

125,

200,

250,

500,

1000,

1250,

2000,

2500,

5000,

10000,

12500,

20000,

25000,

50000,

100000,

125000,

200000,

250000,

500000,

1000000,

1250000,

2000000,

2500000,

5000000,

10000000,

12500000,

20000000,

25000000,

50000000,

100000000,

125000000,

200000000,

250000000,

500000000,

1000000000,

1250000000,

2000000000};



int main()

{

    while(scanf("%d%d",&m,&n)!=EOF)

    {

        if(m>n) swap(m,n);

        int cnt=0;

        for(int i=0;i<45;i++)

        {

            if(m<=num[i] && num[i]<=n) cnt++;

        }

        cout<<cnt<<endl;

    }

    return 0;

}

 

你可能感兴趣的:(number)