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.
Input
The first line of input is the number of test cases T.
The next T lines each have an integer N.
Output
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
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e6+10;
const int INF = 0x3fffffff;
int a[60];
int sz=0;
int f(int n){
sz = 0;
memset(a,0,sizeof(a));
for(int i=2;i*i<=n;i++){
if(n%i==0){
while(n%i==0){
a[sz]++;
n/=i;
}
++sz;
}
}
if(n>1) a[sz++]=1;
sort(a,a+sz);
return a[sz-1];
}
int main(){
int t;
cin>>t;
while(t--){
int n;
scanf("%d",&n);
long long ans = f(n);
cout<<ans<<endl;
}
return 0;
}