问题虫洞:Minimal Power of Prime
黑洞内窥:
给你一个数 n ,求n在唯一分解定理式下的最小指数。(2<= n <= 10^18)
思维光年:
第一次:
由于n的取值非常的大,一开始就开了6w的数组,然后暴力求解,T~~~~
第二次:
加了一个大素数的判定,继续T~~~
第n次:
还是T~~~
正确的求解:
打一个1~5000的素数表(wc?!),然后你用这5000内的素数去质分解n,
由于n有10^18,所以,要是没除尽的话,因子最多也就4个了,
所以幂数大于1的情况有p^4,p^3, p^2 , p1^2*p2^2。
暴力判断;
ACcode:
//#include<bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include<algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <cstring>
#include <string.h>
#include <string>
#include <math.h>
#include <sstream>
using namespace std;
typedef long long ll;
#define MAXN 5000
#define INF 0x3f3f3f3f//将近ll类型最大数的一半,而且乘2不会爆ll
const ll mod = 1000000007;
const double eps = 0.0000001;
bool is[5000];
int prime[5000];
ll tot, n;
void getprime() //欧拉筛
{
memset(is, false, sizeof(is));
tot = 0;
for(int i=2; i<=MAXN; ++i)
{
if(is[i] == false)
prime[tot++] = i;
for(int j=0; j<tot && i*prime[j] <= MAXN; ++j)
{
is[i*prime[j]] = true;
if(i%prime[j] == 0)
break;
}
}
}
ll yueshuSUM(ll x)
{
ll ans = MAXN;
n = x;
for(int i=0; i<tot && prime[i] < n; ++i)
{
if(n%prime[i] == 0)
{
ll k = 0;
while(n%prime[i] == 0)
{
n/=prime[i];
++k;
}
ans = min(ans, k);
}
if(ans == 1)
return ans;
}
// if(n > 1) //不能特判
// ans = 1;
return ans;
}
int main()
{
getprime();
int t;
scanf("%d", &t);
while(t--)
{
ll k, m, sum=0, ans;
scanf("%lld", &k);
ans = yueshuSUM(k);
if(n == 1)
printf("%lld\n", ans);
else
{
if(ans > 4 && pow(floor(pow(n, 1.0/4)+eps), 4) == n)
puts("4");
else if(ans > 3 && pow(floor(pow(n, 1.0/3)+eps), 3) == n)
puts("3");
else if(ans > 2 && pow(floor(pow(n, 1.0/2)+eps), 2) == n)
puts("2");
else
puts("1");
}
}
return 0;
}