i really want to do that,but because of my poor english,i don't know whether i can explain it well
[cpp]
#include <iostream>
using namespace std;
int primes[4800];
int point;
void init()
{
//initial the primes array,from 2 to 46340(which is sqrt(2^31))
primes[0] = 2;
point = 1;
int flag;
for(int i = 3;i < 46340;i += 2)
{
flag = 1;
for(int j = 0;j < point && primes[j] * primes[j] <= i;j++)
{
if(i % primes[j] == 0)
{
flag = 0;
break;
}
}
if(flag) {primes[point++] = i;}
}
}
int count(long long n)
{
int arr[4800],min;
int point_a = 0;
/**********************************************
here i divide n by every primes in the primes[]
if n % primes[] == 0 until the number in primes[]
is larger than n,put the times in arr[].
for example
392 = 2 * 2 * 2 * 7 * 7
than the arr[] will be
arr[0] = 3
arr[1] = 2
***********************************************/
for(long long i = 0;i < 4792 && primes
<= n;i++)
{
if(n % primes == 0)
{
arr[point_a] = 0;
while(n % primes == 0)
{
arr[point_a]++;
n /= primes;
}
point_a++;
}
}
//if n still != 0,n must be larger than 46340,then return 1
if(n != 1)
{
return 1;
}
min = arr[0];
//min store the GCD of numbers in arr[]
for(int j = 1;j < point_a;j++)
{
if (arr[j] < arr[0]) min = arr[j];
if(arr[j] != arr[j - 1])
{
if(arr[j] % arr[j - 1] && arr[j - 1] % arr[j])
// the GCD of arr[j] and arr[j + 1] is 1
{
return 1;
}
}
}
return min;
}
int main()
{
init();
long long n;
while(cin >> n)
{
if(n == 0) break;
if(n < 0) n *= -1;
cout << count(n) << endl;
}
return 0;
}
[/cpp]