Minimal Power of Prime
Problem-solving ideas
Hit \ (N ^ \ frac {1 } {5} \) prime number table therein, for each n, the first decomposed \ (N ^ \ frac {1 } {5} \) prime numbers in the range of decomposition after n to m, if m is equal to 1, the answer is \ (N ^ \ frac {1 } {5} \) primes decomposed inside the minimum number k. Otherwise, continue to break down, then prime numbers are used to break greater than \ (N ^ \ frac {1 } {5} \) , so a maximum of four prime numbers multiplied, so only three cases: \ (^ P . 4 \) , \ (P ^. 3 \) , \ (P ^ 2 \) , \ (P ^ 2 * Q ^ 2 \) , and the answer is the case (P, Q 1 is more than \ (N ^ \ frac 5} {1} {\) primes). For the first two cases, respectively, see \ (m ^ \ FRAC. 1 {{}}. 4 \) , \ (m ^ \ FRAC. 1 {{}}. 3 \) is a number, for a three-four cases, in fact, is the same as long as the look \ (m ^ \ frac {1 } {2} \) is not an integer on the line, the first four of which are not, the answer is 1.
code show as below
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
inline int read(){
int res = 0, w = 0; char ch = 0;
while(!isdigit(ch)){
w |= ch == '-', ch = getchar();
}
while(isdigit(ch)){
res = (res << 3) + (res << 1) + (ch ^ 48);
ch = getchar();
}
return w ? -res : res;
}
ll p(ll a, int b)
{
ll ans = 1;
for(int i = 1; i <= b; i ++)
ans *= a;
return ans;
}
int main()
{
int t;
t = read();
vector<int> vec;
for(int i = 2; i <= 4000; i ++){
bool flg = true;
for(int j = 2; j <= sqrt(i); j ++){
if(i % j == 0){
flg = false;
break;
}
}
if(flg)
vec.push_back(i);
}
while(t --){
ll n;
scanf("%lld", &n);
int ans = 100;
for(int i = 0; i < vec.size(); i ++){
int t = vec[i];
int cnt = 0;
while(n % t == 0){
n /= t;
++cnt;
}
if(cnt)
ans = min(ans, cnt);
}
if(n == 1)
printf("%d\n", ans);
else {
for(int i = 4; i >= 1; i --){
if(i == 1)
printf("1\n");
else {
ll x = max((ll)pow(n, 1.0/i) - 5, 1LL);
bool flg = true;
ll m = p(x, i);
while(m < n){
++ x;
m = p(x, i);
}
if(m == n){
printf("%d\n", min(ans, i));
break;
}
}
}
}
}
return 0;
}