zoukankan      html  css  js  c++  java
  • Magic Number (zoj3622)

    Magic Number (zoj3622)

    Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
    Total Submission(s) : 21   Accepted Submission(s) : 7
    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
    

    开始不理解题意,后来同学给我讲了之后才理解
    题意;得 xy mod y = 0 ,变形即得 (x*10^(y的位数)+y)mod y = 0,

    化简得 x*10^(y的位数) mod y = 0 ,题目说对于任意的 x,y都得成立,

    所以只要 y 是 10^(y的位数) 的因子即可。但是这道题卡时,做的时候老超时,

    到最后不得不把数据范围内的所有数都打出来,没办法,,,我只能说我能力不够啊,,,还是太水了,,,

    附代码:
    /*
    #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;
    }
    
    //我表示时间很漫长,但是你会找到规律的,所以之后的自己写好了,哈哈
    */
    
    /*
    #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<100;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);}
            }
            __int64 a=100,b=125,c=200,d=250,e=500;
            for(;a<pow(2,31);)//有了上面的规律,这样就可以全部输出来了。。。很快的,哈哈
            {
                printf("%I64d  %I64d   %I64d   %I64d   %I64d   ",a,b,c,d,e);
                a*=10;
                b*=10;
                c*=10;
                d*=10;
                e*=10;
            }
            printf("
    ");
        }
        return 0;
    }
    
    */
    
    #include<stdio.h>
      
    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};
    
    int main()//我晕,__int64不然过,,,long long 就过了,错误是 Getting complication error information failed!  求解释!
    {
        long long int m,n;
        while(scanf("%lld%lld",&m,&n)!=EOF)
        {
            int i,count=0;
            for(i=0;i<55;i++)
            {
                if(m<=a[i]&&a[i]<=n)
                    count++;
                if(a[i]>n)
                    break;
            }
            printf("%lld
    ",count);
        }
        return 0;
    }
    
    

    这是第一个程序,,,寻找规律。

    然后第二个程序,就出来了。


    太心酸了,用int64,PE了N次,改longlong,秒过,求大神解答。
    
    
  • 相关阅读:
    面向对象课程第三次博客总结
    面向对象课程多线程总结
    23种设计模式整理
    java中synchronized与lock的理解与应用
    关于MySQL查询优化
    mysql操作规范建议
    Linux中实体链接与符号链接详解
    获取本地ipv4地址方法(go语言)
    分库分表与负载均衡的一致性hash算法
    golang闭包的一个经典例子
  • 原文地址:https://www.cnblogs.com/yuyixingkong/p/3432163.html
Copyright © 2011-2022 走看看