poj 1730
就是求一个数最大能开多少次方,一开始没注意到有负数的情况。负数要另外处理。
//============================================================================
// Name : 1730.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n, k;
int t, num, tag;
int main() {
freopen("a.txt", "r", stdin);
while(scanf("%d", &n)&&n){
if(n > 0){
t = sqrt(n);
tag = 0;
for(int i = 2;i <= t;i++){
num = 0;
k = n;
while(k%i == 0){
++num;
k /= i;
}
if(k == 1){
printf("%d\n", num);
tag = 1;
break;
}
}
if(tag == 0){
printf("1\n");
}
}
else if(n < 0){
t = sqrt(-n);
tag = 0;
for(int i = -2;i >= -t;i--){
num = 0;
k = n;
while((-k)%(-i) == 0){
++num;
k /= i;
}
if(k == 1){
printf("%d\n", num);
tag = 1;
break;
}
}
if(tag == 0){
printf("1\n");
}
}
}
return 0;
}

浙公网安备 33010602011771号