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,我们可以任何整数x放在Y前,组成新的数XY都能整除y,问区间内这个y有几个
思路:我们可以发现这些数都是由规律的,也就是通过1,2,5,25,125这几个数推导出来的,然后这道题就是个简单的打表了
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int a1[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000}; int a2[10] = {2,20,200,2000,20000,200000,2000000,20000000,200000000,2000000000}; int a3[10] = {5,50,500,5000,50000,500000,5000000,50000000,500000000}; int a4[10] = {25,250,2500,25000,250000,2500000,25000000,250000000}; int a5[10] = {125,1250,12500,125000,1250000,12500000,125000000,1250000000}; int main() { int ans,n,m,i; while(~scanf("%d%d",&n,&m)) { ans = 0; if(n>m) swap(n,m); for(i = 0;i<10;i++) if(n<=a1[i] && a1[i]<=m) ans++; for(i = 0;i<10;i++) if(n<=a2[i] && a2[i]<=m) ans++; for(i = 0;i<9;i++) if(n<=a3[i] && a3[i]<=m) ans++; for(i = 0;i<8;i++) if(n<=a4[i] && a4[i]<=m) ans++; for(i = 0;i<8;i++) if(n<=a5[i] && a5[i]<=m) ans++; printf("%d\n",ans); } return 0; }