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
Author: QU, Zhe
Contest: ZOJ Monthly, July 2012
//下午月赛的第一题
//开始少了2个数,郁闷了
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <stack>
using namespace std;
int dp[100];
int nu;
void set()
{ dp[nu++]=1;
int r[5]={1,2,4,5,8};
int i,j;
for(i=10;i<=1000000000;i*=10)
{
for(j=0;j<5;j++)
if(i%r[j]==0)
dp[nu++]=i/r[j];
}
}
int main()
{
set();
int i,k;
sort(dp,dp+nu);
dp[nu++]=1250000000;
dp[nu++]=2000000000;
int n,m;
while(scanf("%d%d",&m,&n)!=EOF)
{
for(k=i=0;i<nu;i++)
if(m<=dp[i]&&n>=dp[i])
k++;
printf("%d\n",k);
}
return 0;
}