zoukankan      html  css  js  c++  java
  • poj magic number

                              Problem H

    Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
    Total Submission(s) : 24   Accepted Submission(s) : 8
    Problem 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
    怎样打表
    这些数都是有规律的从100开始后面都只是加了个0而已,所以可以很快找出来。pow(2,31)=2147483648;
     1 #include<stdio.h>
     2 #include<math.h>
     3 int main()
     4 {
     5       long long int a[55]={1,2,5,10,20,25,50,100,125,200,250,500,1000,1250,2000,2500,5000,10000,12500,20000,25000,50000,100000,125000,200000,250000,500000,1000000,1250000,2000000,2500000,5000000,10000000,12500000,20000000, 25000000, 50000000,100000000 ,125000000, 200000000, 250000000, 500000000,1000000000 ,1250000000, 2000000000, 2500000000,5000000000,10000000000 ,12500000000, 20000000000};
     6         long long m,n,i,t;//不能用I64,wa了用long long,而且vc编译器是非法的。
     7       while(~scanf("%lld%lld",&m,&n))
     8       {
     9           t=0;
    10           for(i=0;i<55;i++)
    11           {
    12               if(a[i]>=m&&a[i]<=n)
    13                 t++;
    14               if(a[i]>n)
    15                   break;
    16           }
    17           printf("%lld
    ",t);
    18       }
    19    return 0;
    20 }

    把数组的那些数是怎样弄出来的代码:

    #include<stdio.h>
    #include<math.h>
    int main()
    {
        __int64 x,y,t=0,m,k;
        while(scanf("%I64d%I64d",&x,&y)!=EOF)
        {
            int i,j;
            k=0;
            for(i=1;i<pow(2,31);i++)
            {
                t=0;
                m=i;
                while(m)
                {
                  t++;m/=10;
                }
                int p=1;
                for(j=1;j<=i;j++)
                {
                    if((j*(__int64)pow(10,t))%i)
                    {
                        p=0;
                        break;
                    }
                }
                if(p)
                {
                    printf("%I64d  ",i);
                }
            }
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    【Exgcd】斩杀线计算大师
    【DP】操作集锦
    【DP】被3整除的子序列
    【DFS序】【CF-1328E】Tree Queries
    【规律】【CF1327-D】Carousel
    Luogu P4774 屠龙勇士
    LOJ 10149 凸多边形的划分
    Luogu P4036 火星人
    Luogu P3193 GT考试
    CF 986C AND Graph
  • 原文地址:https://www.cnblogs.com/cancangood/p/3432217.html
Copyright © 2011-2022 走看看