zoj Majic Number(3622)

来源:互联网 发布:淘宝人气女装店铺 编辑:程序博客网 时间:2024/05/22 13:23

A positive number y is called magic number if for every positive integerx it satisfies that put y to the right of x, which will form a new integerz, 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 andn(m, n inclusively).

Sample Input

1 11 10

Sample Output

14

首先:我们写个程序写下前一10000 里面有哪些数。

#include <cstdio>#include <cstring>#include <cmath>int main(){int i,j;int temp;bool flag;int cnt = 0;for(i = 1;i<10000;i++){flag = true;for(j = 1;j<=9;j++){if(i<10) temp=j*10+i;else if(i<100) temp = j*100+i;else if(i<1000) temp = j*1000+i;else if(i<10000) temp = j*10000+i;if(temp%i!=0) {flag = false;break;}}if(flag) {printf("%d\n",i);cnt++;}}printf("%d\n",cnt);return 0;}
1
2
5
10
20
25
50
100
125
200
250
500
1000
1250
2000
2500
5000
17

我们发现这些数都只会是 1,2,5,25,125 的倍数。

于是:

#include <cstdio>#define maxn 10000long long a[] = {1,2,5,25,125};int main(){int n,m;while(scanf("%d%d",&n,&m)!=EOF){int ans = 0;for(int i = 0;i<5;i++){long long x = a[i];while(x<=m){if(x>=n) ans++;x*=10;}}printf("%d\n",ans);}return 0;}

伟大的梦想成就伟大的人,从细节做好,从点点滴滴做好,从认真做好。


0 0
原创粉丝点击