ZOJ3622:Magic Number

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 zz mod y = 0.

Input

The input has multiple cases, each case contains two positve integers mn(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(mn 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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值