#include<iostream>
#include
<math.h>
using namespace std;
int main()
{
    
long long mm,i,n;
    
double m,p;
    
while(1)
    
{
        scanf(
"%I64d",&n);
        
if(!n)break;
        
        
if(n>0)
        
{
            i
=(long long)(log((double)n)/log(2.0000000))+1;
            
for(;i>1;--i)
            
{
                m
=pow((double)n,1.0000000/(double)i);
                mm
=(long long)m;
                
if(m-(double)mm<1e-12||(double)mm+1-m<1e-12)
                
{
                    printf(
"%I64d\n",i);
                    
break;
                }

            }

            
if(i==1)
                printf(
"1\n");
        }

        
else
        
{
            n
=-n;
            i
=(long long)(log((double)n)/log(2.0000000))+1;
            
if(i%2==0)--i;
            
for(;i>1;i-=2)
            
{
                m
=pow((double)n,1.0000000/(double)i);
                mm
=(long long)m;
                
if(m-(double)mm<1e-12||(double)mm+1-m<1e-12)
                
{
                    printf(
"%I64d\n",i);
                    
break;
                }

            }

            
if(i==1)
                printf(
"1\n");
        }

    }

    
return 0;
}
直接枚举。
貌似pow()函数比log()快。之前用log()函数枚举对数的底,超时。
对输入要分正负。枚举的范围是[1,log((double)n)/log(2.0000000)+1]。
当x为正数时,p取以上区间所有整数,在符合的p中取最大。
当x为负数时,将x转化为正数处理,p取以上区间所有奇数(因为只有奇数次幂才可能等于负数),
在符合的p中取最大。