The final state of the last bulb is determined by the number of factors of N. only the number which is the square of a number has an odd number of factors, thus it has a state of "yes ".
Code:
- /*************************************** ************************************
- * Copyright (c) 2008 by Liu kaipeng *
- * Liukaipeng at gmail dot com *
- **************************************** ***********************************/
- /* @ Judge_id 00000 10110 C ++ "light, more light "*/
- # Include <algorithm>
- # Include <cmath>
- # Include <cstdio>
- # Include <cstring>
- # Include <deque>
- # Include <fstream>
- # Include <iostream>
- # Include <list>
- # Include <map>
- # Include <queue>
- # Include <set>
- # Include <stack>
- # Include <string>
- # Include <vector>
- Using namespace STD;
- Int main (INT argc, char * argv [])
- {
- # Ifndef online_judge
- Freopen (string (argv [0]) + ". In"). c_str (), "r", stdin );
- Freopen (string (argv [0]) + ". Out"). c_str (), "W", stdout );
- # Endif
- /* The final state of the last bulb is determined by the number of factors
- Of N. Only the number which is the square of a number has odd number
- Factors, thus it has a state of "yes ".*/
- For (unsigned int N; CIN >>n & n! = 0 ;){
- Unsigned int r = SQRT (N );
- If (R * r = N) cout <"Yes/N ";
- Else cout <"No/N ";
- }
- Return 0;
- }