TIOJ 1851 - 第五顆星球的點燈人

Link: http://tioj.ck.tp.edu.tw/problems/1851

基本上就是求N有幾個因數,如果有偶數個輸出no,奇數個輸出yes
由於因數是兩兩成對的,所以只要判斷n是不是一個完全平方數即可

AC code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);

unsigned n;
while(cin>>n,n)
{
unsigned t=sqrt(n);
if(t*t==n)
cout<<"yes\n";
else
cout<<"no\n";
}
}