zoukankan      html  css  js  c++  java
  • [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
    

    分析:
    设y有k位数,则需要满足 (x*10^k+y)%y==0
    --> (x*10^k%y+0)%y==0
    --> x*10^k%y==0
    --> 由于x是任意的,假设x为质数,则需要满足(10^k)%y==0
    直接判断会超时,先打表。
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    #include <cmath>
    #include <string>
    using namespace std;
    #define N 100010
    
    int n,m;
    int len;
    int num[N]=
    {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};
    
    int main()
    {
        while(scanf("%d%d",&m,&n)!=EOF)
        {
            if(m>n) swap(m,n);
            int cnt=0;
            for(int i=0;i<45;i++)
            {
                if(m<=num[i] && num[i]<=n) cnt++;
            }
            cout<<cnt<<endl;
        }
        return 0;
    }
    趁着还有梦想、将AC进行到底~~~by 452181625
  • 相关阅读:
    JS框架设计读书笔记之-选择器引擎02
    JS框架设计读书笔记之-选择器引擎01
    JS框架设计读书笔记之-小知识
    JS框架设计读书笔记之-函数
    JS框架设计读书笔记之-核心模块
    7.19 NOIP模拟6
    一 网络基础之网络协议篇
    Socket 网络编程
    Python 常用模块
    类的特殊成员
  • 原文地址:https://www.cnblogs.com/hate13/p/4139974.html
Copyright © 2011-2022 走看看