UVa Problem Solution: 10110 - Light, More Light

来源:互联网 发布:java转ansi utf-8 编辑:程序博客网 时间:2024/05/18 11:25
 
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:
  1. /***************************************************************************
  2.  *   Copyright (C) 2008 by Liu Kaipeng                                     *
  3.  *   LiuKaipeng at gmail dot com                                           *
  4.  ***************************************************************************/
  5. /* @JUDGE_ID 00000 10110 C++ "Light, More Light" */
  6. #include <algorithm>
  7. #include <cmath>
  8. #include <cstdio>
  9. #include <cstring>
  10. #include <deque>
  11. #include <fstream>
  12. #include <iostream>
  13. #include <list>
  14. #include <map>
  15. #include <queue>
  16. #include <set>
  17. #include <stack>
  18. #include <string>
  19. #include <vector>
  20. using namespace std;
  21.      
  22. int main(int argc, char *argv[])
  23. {
  24. #ifndef ONLINE_JUDGE
  25.   freopen((string(argv[0]) + ".in").c_str(), "r", stdin);
  26.   freopen((string(argv[0]) + ".out").c_str(), "w", stdout);
  27. #endif
  28.   /* The final state of the last bulb is determined by the number of factors
  29.      of n. Only the number which is the square of a number has odd number of
  30.      factors, thus it has a state of "yes". */
  31.   for (unsigned int n; cin >> n && n != 0; ) {
  32.     unsigned int r = sqrt(n);
  33.     if (r * r == n) cout << "yes/n";
  34.     else cout << "no/n";
  35.   }
  36.   return 0;
  37. }


原创粉丝点击