int main double absx int found while scanf lf if return absx fabs for

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int main()
{
double x, absx, b, r;
int p, found=0;
while ( (scanf("%lf",&x)==1))
{
if (x==0) return 0;
absx = fabs(x);
for (b=2; b*b<=absx; b++)
{
r = b*b;
p = 2;
while ( r< absx)
{
p++;
r=r*b;
}
if (r == absx)
{
if (x>0 || p%2)
{
printf("%d\n",p);
found = 1;
break;
}
}
}
if (!found) printf("1\n");
found = 0;
}
}