zoukankan      html  css  js  c++  java
  • LightOJ

    Dr. Mob has just discovered a Deathly Bacteria. He named it RC-01. RC-01 has a very strange reproduction system. RC-01 lives exactly x days. Now RC-01 produces exactly p new deadly Bacteria where x = bp (where b, p are integers). More generally, x is a perfect pth power. Given the lifetime x of a mother RC-01 you are to determine the maximum number of new RC-01 which can be produced by the mother RC-01.


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


    Each case starts with a line containing an integer x. You can assume that x will have magnitude at least 2 and be within the range of a 32 bit signed integer.


    Output
    For each case, print the case number and the largest integer p such that x is a perfect pth power.


    Sample Input
    3
    17
    1073741824
    25
    Sample Output
    Case 1: 1
    Case 2: 30

    Case 3: 2

    #include<stack>
    #include<queue>
    #include<math.h>
    #include<vector>
    #include<string>
    #include<stdio.h>
    #include<map>
    #include<iostream>
    #include<string.h>
    #include<algorithm>
    #define maxn 1000005
    #define maxm 10000005
    #define MAXN 100005
    #define MAXM 10005
    #define mem(a,b) memset(a,b,sizeof(a))
    #define ll long long
    #define inf 0x3f3f3f3f
    using namespace std;
    bool vis[maxm+5];
    ll tot;
    ll p[maxn];
    void get_prime(){
         tot=0;
        mem(vis,true);
        for(ll i=2;i<=maxm;i++){
            if(vis[i]){
                p[tot++]=i;
                for(ll j=i*i;j<=maxm;j+=i)vis[j]=false;
            }
        }
    }
    int main(){
        get_prime();
        int t,test=0;
        scanf("%d",&t);
        while(t--){
         ll n;scanf("%lld",&n);
         ll m=n;
         n=abs(n);
         ll x=0,ans=-1;
         while(p[x]<=n&&x<tot){
            ll y=0;
            while(n%p[x]==0){y++;n/=p[x];}
            x++;
            if(ans==-1)ans=y;
            else
                ans=__gcd(ans,y);
         }
         if(n>1)ans=__gcd(ans,(ll)1);
         if(m<0){
            while(ans%2==0)ans/=2;
         }
         else if(m==1||m==0)
            ans=1;
            printf("Case %d: %lld
    ",++test,ans);
        }
    }

  • 相关阅读:
    算法学习(二)——树状数组求逆序数
    ZOJ 2412 Farm Irrigation
    排列的生成算法(一)
    汉诺塔递归实现
    汇编(五)
    汇编(四)
    汇编(三)
    汇编(二)
    0103MySQL中的B-tree索引 USINGWHERE和USING INDEX同时出现
    0103如何通过索引长度确定是否使用全索引
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053223.html
Copyright © 2011-2022 走看看