题目链接:hdu_5752_Sqrt Bo
题意:
给你一个数,问你最少要开多少次方才能为1
题解:
我们发现如果给的数大于232 那么肯定在5次以内是开不出来的,所以直接输出TAT,然后小于的就模拟一下,注意1和0的特判就行
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 typedef long long ll; 5 const ll INF = ((ll)1 << 32) - 1; 6 char inf[15] ="4294967295"; 7 char n[105]; 8 int len; 9 void fail() 10 { 11 printf("TAT "); 12 } 13 void success() 14 { 15 ll ans = 0; 16 for (int i = 0; i < len; i++) ans = ans * 10 + n[i] - '0'; 17 if (ans == 1) {printf("1 "); return;} 18 else if (ans == 0) {printf("TAT "); return;} 19 int cnt = 0; 20 while (ans > 1) {ans = sqrt(ans); cnt++;} 21 printf("%d ", cnt); 22 } 23 int main() 24 { 25 while (~scanf("%s", n)) 26 { 27 len = strlen(n); 28 if (len > 10) fail(); 29 else if (len < 10) success(); 30 else 31 { 32 for (int i = 0; i < 10; i++) 33 if (n[i] > inf[i]) {fail(); break;} 34 else if (n[i] < inf[i]) {success(); break;} 35 else if (i == 9 && n[i] == inf[i]) {success(); break;} 36 } 37 } 38 return 0; 39 }