題意:
有個人管理一條走廊的燈泡,當走廊有'n'個燈泡,編號1~n,預設是關閉的,他會來回走n趟,第i趟他把編號能被i整除的燈泡開關切換,本題問編號n的燈泡最後是亮還是暗。
想法:
n只有在其因數的時候被切換,因此如果因數個數為偶數,那麼最後是暗的,反之如果為基數則為亮的,而只有能被開平方根的時候因數個數才會為奇數。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cmath> | |
using namespace std; | |
typedef unsigned int uint; | |
int main() | |
{ | |
uint n; | |
while (scanf("%u",&n)){ | |
if (!n) break; | |
uint a = sqrt(n); | |
if (a * a == n) printf("yes\n"); | |
else printf("no\n"); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言