题目描述
You all know about factorization of an integer. Here we want you to factor a number into as few factors
as possible. That is easy, you say, just have the number itself, and that will be the smallest number of
factors i.e. 1.
But wait, I haven’t finished — each of the factors that you find must be square-free. A square-free
number, however you factor it, won’t have any factor that is a perfect square. Of course, you can never
include 1 as a factor.
输入
The first line of input is the number of test cases T.
The next T lines each have an integer N.
输出
For each testcase, output the smallest number of square-free factors.
Constraints:
• T ≤ 104
• 2 ≤ N ≤ 106
Explanation:
6 can be factored as just 6 (further factorable as 2 × 3 only, and hence square free), a single factor.
8 has to be factored as 2 × 2 × 2 so that all factors are square-free.
样例
Sample Input
2
6
8
Sample Output
1
3
题意
唯一分接定理 求的是质因子最的幂 QAQ
AC代码
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a))
#define ls st<<1
#define rs st<<1|1
const int MAXN = 1e6+10;
int prime[MAXN];
void getPrime()
{
memset(prime, 0, sizeof(prime));
for (int i = 2; i <= MAXN; i++)
{
if (!prime[i])
{
prime[++prime[0]] = i;
}
for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++)
{
prime[prime[j] * i] = 1;
if (i % prime[j] == 0)
{
break;
}
}
}
}
int main() {
getPrime();
int T;
cin >> T;
int k = 0;
while(T--) {
LL n;
cin >> n;
int ans = 0;
for(int i = 1; i < prime[0] && prime[i] <= n; i++) {
if(n%prime[i]==0) {
int kk = 0;
while(n%prime[i]==0) {
n /= prime[i];
kk++;
}
ans = max(kk,ans);
}
}
cout << ans << endl;
}
return 0;
}