给出一个x,求满足x = b^p,p最大是多少?
直接枚举满足要求的p的个数,,
进行质因数分解也可以,
x = p1^e1 * p2^e2 * p3^e3 ……. * pn^en
p = gcd (e1,e2,…….en)
#include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<iomanip>
#include<map>
#include<vector>
#include<queue>
#include<stack>
//#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define gamma 0.57721566490153286060651209008240243104215933593992
const double Pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MAXN=1000010;
int main()
{
    int t;
    cin>>t;
    int casee=1;
    while(t--)
    {
        LL n;
        cin>>n;
        LL ans=1;
        int flag=1;
        if(n<0)
        {
            n=-n;
            flag=-1;
        }
        for(int i=2;i<=sqrt(n);++i)
        {
            LL cnt=0;
            LL tmp=n;
            while(tmp%i==0)
            {
                cnt++;
                tmp/=i;
            }
            if(tmp==1)
            {
                if(flag==-1 && cnt%2==0)
                continue;
                ans=max(ans,cnt);
            }
        }
        printf("Case %d: %lldn",casee++,ans);
    }
    return 0;
}
- 版权声明:本文基于《知识共享署名-相同方式共享 3.0 中国大陆许可协议》发布,转载请遵循本协议
- 文章链接:http://www.carlstedt.cn/archives/96 (转载时请注明本文出处及文章链接)



发表评论
快来吐槽一下吧!