poj 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



#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
long long int a[100];
int main()
{
    long long int n,m,i,j,k,sum;
    a[0]=1;a[1]=2;a[2]=5,a[3]=25,a[4]=125;
    k=5;
	sum=1;
    for(i=1;i<=10;i++)
	{
		a[k++]=sum*10;sum*=10;
	}
	sum=10;
	for(i=1;i<=10;i++)
	{
		a[k++]=sum*2;sum*=10;
	}
	sum=5;
	for(i=1;i<=10;i++)
	{
		a[k++]=sum*10;sum*=10;
	}
	sum=10;
	for(i=1;i<=10;i++)
	{
		a[k++]=sum*25;sum*=10;
	}
	sum=10;
	for(i=1;i<=8;i++)
	{
		a[k++]=sum*125;sum*=10;
	}
    sort(a,a+k);
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
		int y=0;
		for(i=0;i<k;i++)
		{
			if(a[i]>=n&&a[i]<=m)y++;
		}
		printf("%d
",y); } return 0; }

좋은 웹페이지 즐겨찾기