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

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;
}

转载于:https://www.cnblogs.com/372465774y/archive/2012/07/29/2614313.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值