zoukankan      html  css  js  c++  java
  • lightoj-1028

    1028 - Trailing Zeroes (I)
    PDF (English) Statistics Forum
    Time Limit: 2 second(s) Memory Limit: 32 MB
    We know what a base of a number is and what the properties are. For example, we use decimal number system, where the base is 10 and we use the symbols - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. But in different bases we use different symbols. For example in binary number system we use only 0 and 1. Now in this problem, you are given an integer. You can convert it to any base you want to. But the condition is that if you convert it to any base then the number in that base should have at least one trailing zero that means a zero at the end.

    For example, in decimal number system 2 doesn't have any trailing zero. But if we convert it to binary then 2 becomes (10)2 and it contains a trailing zero. Now you are given this task. You have to find the number of bases where the given number contains at least one trailing zero. You can use any base from two to infinite.

    Input
    Input starts with an integer T (≤ 10000), denoting the number of test cases.

    Each case contains an integer N (1 ≤ N ≤ 1012).

    Output
    For each case, print the case number and the number of possible bases where N contains at least one trailing zero.

    Sample Input
    Output for Sample Input
    3
    9
    5
    2
    Case 1: 2
    Case 2: 1
    Case 3: 1
    Note
    For 9, the possible bases are: 3 and 9. Since in base 3; 9 is represented as 100, and in base 9; 9 is represented as 10. In both bases, 9 contains a trailing zero.

    #include<iostream>
    #include<cstdio> 
    #include<cmath>
    using namespace std;
    
    typedef long long ll;
    
    int prime[1000000];
    int judge[1000100]={false};
    int cnt;
    
    void Prime(){
        
        prime[0] = 2;
         cnt = 1;
        for(ll i=3;i<1000010;i+=2){
            if(!judge[i]){//cout<<i<<endl;
                for(ll j=i*i;j<1000010;j+=i) judge[j] = true;
                prime[cnt++] = i;
            }
        }    
    }
    
    int main(){
        Prime();
        int T,save;
        ll sum,n;
        scanf("%d",&T);
        for(int t=1;t<=T;t++){
            
            scanf("%lld",&n);
            
            sum = 1;
            for(int i=0;i<cnt&&prime[i]*prime[i]<=n;i++){ // prime[i]*prime[i]<=n 是个很重要的优化点
                save = 0;
                while(n%prime[i]==0){
                    save++;
                    n = n/prime[i];
                }
                sum *= save+1;
            }
            if(n!=1) sum*=2;
            sum--;
            printf("Case %d: %lld
    ",t,sum);        
        }
        
        return 0;
    ;}
  • 相关阅读:
    HttpServletRequest字符集问题
    原码反码补码
    无符号1byte转int
    初识spark的MLP模型
    冗余系统必要性
    shiro的rememberMe不生效
    阅读笔记-异常
    优雅的处理异常
    使用Maven搭建SpringMVC
    Jmeter发送soap请求
  • 原文地址:https://www.cnblogs.com/yuanshixingdan/p/5550510.html
Copyright © 2011-2022 走看看