刚开始分析是直接枚举,1~sqrt(n),想着想着都是偶数对啊,应该全是no,但是样例有yes,再细想,就发现如果是平方数那就没配对了,这样只需要判断是否平方数,可惜交的时候WA啊!!也不知道为什么,把int改为long就AC了,但题目说n <= 2^32 - 1啊。。int范围啊,怎么回事。。。
#include <iostream> #include <cmath> #include <string> using namespace std; //#define TEST int main() { #ifdef TEST freopen("input.txt", "r", stdin); #endif long n; while(cin >> n && n != 0) { long m = floor(sqrt((float)n)); if(m * m != n) cout << "no/n"; else cout << "yes/n"; } return 0; }