UVa Problem Solution: 10110 - Light, More Light

 
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. }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值