Minimal Power of Prime
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
题意:
求N以内素因子幂的最小值
分析:
一开始用Pollard_Rho交了3次,全TTTTTT了,tcl(太菜了),确实处理的方法有点暴力,如果那么简单,做的人就不会那么少了
看了别人家的孩子做的,原来这是有点东西啊,
先求1e4里面的素因子,这样求的是有1229个,为什么要求1e4个之内的呢,因为T组数据,题目中说 T ≤ 50000,那么这就是5e7的复杂度(需要暴力这些素数),可以在1s内飘过,然后还有一个地方就是,第1229个素数(9973^4)的四次方是9,892,436,613,211,441这个,第1230个素数是10007,也就是说第1229个素数之后最坏的情况是还有4个素因子相乘
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstring>
#include<set>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
const int N=1e5+10;
const ll INF=0x3f3f3f3f3f3f3f3f;
int maxn=1e5+10;
bool is_prime[20010];
ll prime[20010],tot;
void get_prime(){
for(int i=2;i<=10000;i++){
if(!is_prime[i]){
prime[tot++]=i;
for(int j=i+i;j<=10000;j+=i){
is_prime[j]=1;
}
}
}
}
int solve(ll n){
int ans=(ll)1<<30;
for(int i=0;i<tot;i++){//一个或者多个的
if(n%prime[i]==0){
int cnt=0;
while(n%prime[i]==0){
n/=prime[i];
cnt++;
}
ans=min(ans,cnt);
if(ans==1) return ans;//提前结束
}
}
if(n!=1){
ll k1= sqrt(n);
if(k1*k1==n){//2个或者4个的
ll k2=sqrt(k1);
if(k2*k2==k1){
return min(ans,4);
}else
return min(ans,2);
}else{//三个或者1个的
ll lb=0,ub=1000000;//1e6的三次方刚好是1e18,看n是不是某个数的三次方,用二分找会快一点
while(ub>=lb){
ll mid=(ub+lb)/2;
if(mid*mid*mid==n)//找到了,说明剩下的数是一个可以开三次方的数
return min(ans,3);
if(mid*mid*mid>n)
ub=mid-1;
else
lb=mid+1;
}
return min(ans,1);//没有找到,那么就说明剩下的是一个大素数了
}
}else{
return ans;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
get_prime();
int T;ll n;
scanf("%d",&T);
while(T--){
scanf("%lld",&n);
printf("%d\n",solve(n));
}
return 0;
}