ACM UVA-10622

Prime+GCD

int gcd(int a,int b){
    return b == 0?a:gcd(b,a%b);
}
int main(int argc, char const* argv[])
{
    bool prime[65540];
    long long ppp[65540];
    int power[65540];
    int m = 0;
    for(long long i = 2;i<65540;i++){
        if(!prime[i]){
            ppp[m++] = i;
            for(long long j = i*i;j<65540;j = j+i){
                prime[j] = true; 
            }
        }

    }

    long long n;
    while(~scanf("%lld",&n) && n != 0){
        bool flag = 0;
        if(n<0){
            n = -n;
            flag = 1;
        }
        int t = 0;
        for(int i = 0; ppp[i]*ppp[i]<= n;i++) {
            if( n%ppp[i] == 0){
                int count = 0;
                while(n%ppp[i] == 0){
                    n = n/ppp[i]; 
                    count++;
                }
                power[t++] = count;
            }
        }
        if(n>1){
            power[t++] = 1;
        }
        int g = 0;
        for(int i = 0;i<t;i++){
            g = gcd(power[i],g);
        }
        if(flag){
            while(g%2 == 0){
                g = g/2; 
            }
            printf("%d\n",g);
        }else{
            printf("%d\n",g);
        }
    }

    return 0;
}