Problem Description
You are given a positive integer n > 1. Consider all the different prime divisors of n. Each of them is included in the expansion n into prime factors in some degree. Required to find among the indicators of these powers is minimal.
Input
The first line of the input file is given a positive integer T ≤ 50000, number of positive integers n in the file. In the next T line sets these numbers themselves. It is guaranteed that each of them does not exceed 10^18.
Output
For each positive integer n from an input file output in a separate line a minimum degree of occurrence of a prime in the decomposition of n into simple factors.
Sample Input
5 2 12 108 36 65536
Sample Output
1 1 2 2 16
Source
2019 Multi-University Training Contest 4
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6623
题目大意:给你一个数n,把它分解为素数的幂次的乘积的形式:n=p1^e1 * p2^e2 * .......pk^ek 求最小的幂次是多少
例如:16=2^4 ans=4, 108=2^2 * 3^3 ans=2
思路:因为n到10^18 所以我们不能直接处理出到n^1/2的素数,但是我们可以处理出到n^1/5的素数,把存在幂次可能为5的素因子都先分解出来, 那么现在的n的素因子的幂次最为4,那么就判这个数是不是一个数的4次方如果是的话ans=min(ans,4),
如果不是的话再判n是不是一个数的3次方,如果是的话ans=min(ans,3),如果不是的话就判n是不是一个数的平方,如果是ans=min(ans,2),如果不是那么ans=1
这样就可以把复杂度降到O(T*N^1/5 / log(N)).
代码:
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
const int N=500005;
int a[10005],tot;
ll b[10005];
void init()
{
tot=0;
a[0]=a[1]=1;
for(int i=2;i<=10000;i++)
if(a[i]==0)
{
b[tot++]=(ll)i;
for(int j=i*2;j<=10000;j+=i)
a[j]=1;
}
}
int fun(ll n)
{
ll l=1,r=pow(n*1.0,1.0/3)+1,mid;
while(l<=r)
{
mid=(l+r)>>1;
ll y=mid*mid*mid;
if(y==n) return 1;
else if(y>n) r=mid-1;
else l=mid+1;
}
return 0;
}
int main()
{
init();
int t;
scanf("%d",&t);
while(t--)
{
ll n;
scanf("%lld",&n);
int x,ans=100;
for(int i=0;i1)
{
ll m1=(ll)sqrt(sqrt(n*1.0));
ll m2=(ll)sqrt(n*1.0);
if((m1*m1*m1*m1)==n) ans=min(ans,4);
else if(fun(n)==1) ans=min(ans,3);
else if(m2*m2==n) ans=min(ans,2);
else ans=1;
printf("%d\n",ans);
}
}
return 0;
}