思路
一般情况下,一个数字( x x x) 的因子 ( n n n) 都是成对出现的,如 n n n 和 x n \dfrac{x}{n} nx,除了 n = x n n = \dfrac{x}{n} n=nx 的时候。
n = x n ⇒ n 2 = x ⇒ n = x n = \dfrac{x}{n} \Rightarrow n ^ 2 = x \Rightarrow n = \sqrt{x} n=nx⇒n2=x⇒n=x
-
当 x x x 为完全平方数时, x x x 有奇数个因子 ( x \sqrt{x} x 与若干对因子)。
-
当 x x x 不为完全平方数时, x x x 有偶数个因子(若干对因子)。
代码
#include<bits/stdc++.h>
using namespace std;
signed main() {
long long a;
scanf("%lld",&a);
for(int i = 1;i <= a;i++) {
long long b;
scanf("%lld",&b);
long long c = sqrt(b);
if(c * c == b) printf("Case %d: Yes\n",i);
else printf("Case %d: No\n",i);
}
}