ZOJ 3622 Magic Number 打表找规律

A - Magic Number

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Appoint description:
 

Description

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

思路:首先我们得用数学方法推出 只要满足10^ans%a==0,就是magic数,ans指的是a这个数的位数
题解:找规律,然后人工打表……
#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
",ans);
    }

    return 0;
}
原文地址:https://www.cnblogs.com/qscqesze/p/4316705.html