Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 14512 | Accepted: 3263 |
Description
Input
Output
Sample Input
17 1073741824 25 0
Sample Output
1 30 2
Source
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <cmath>
#define N 50001
using namespace std;
bool h[N];
int rc[5555];
int nt;
void set()
{
int i,j,k=1;
for(i=4;i<N;i+=2)
h[i]=1;
for(i=3;i<=300;i+=2)
if(!h[i])
{
for(j=i*i;j<N;j+=i)
h[j]=1;
}
for(i=3;i<N;i+=2)
if(!h[i])
rc[k++]=i;
rc[0]=2;
nt=k;
}
int main()
{
set();
__int64 x;
int i,a[20],k,Min;
bool b,f;
while(scanf("%I64d",&x),x)
{ memset(a,0,sizeof(a));
f=0;
if(x<0) {x=-x,f=1;}
k=0;
for(i=0;i<nt;i++)
{ b=0;
while(x%rc[i]==0)
{
b=1;
a[k]++;
x=x/rc[i];
}
if(b) k++;
if(x==1) break;
}
if(x>1) a[k]++,k++;
for(Min=100,i=0;i<k;i++)
Min=min(Min,a[i]);
for(b=1,i=0;i<k;i++)
if(a[i]%Min)
{b=0;break;}
if(Min==1){ printf("1\n");continue;}
if(b)
{
if(f&&Min%2==0)
{
while(Min%2==0)
Min/=2;
}
printf("%d\n",Min);
}
else
printf("1\n");
}
return 0;
}