HDOJ 2053 Switch Game
2016-04-03 17:17
218 查看
Problem Description
There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).
Input
Each test case contains only a number n ( 0< n<= 10^5) in a line.
Output
Output the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).
Sample Input
1
5
Sample Output
1
0
Hint
hint
Consider the second test case:
The initial condition : 0 0 0 0 0 …
After the first operation : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation : 1 0 0 1 0 …
The later operations cannot change the condition of the fifth lamp any more. So the answer is 0.
The initial condition : 0 0 0 0 0 …
After the first operation : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation : 1 0 0 1 0 …
这是一个例子,分析这个例子,你可以推断出题目的意思。暴力达标的话会超时,因为要用两层10^5,
There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).
Input
Each test case contains only a number n ( 0< n<= 10^5) in a line.
Output
Output the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).
Sample Input
1
5
Sample Output
1
0
Hint
hint
Consider the second test case:
The initial condition : 0 0 0 0 0 …
After the first operation : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation : 1 0 0 1 0 …
The later operations cannot change the condition of the fifth lamp any more. So the answer is 0.
The initial condition : 0 0 0 0 0 …
After the first operation : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation : 1 0 0 1 0 …
这是一个例子,分析这个例子,你可以推断出题目的意思。暴力达标的话会超时,因为要用两层10^5,
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int k=0; for(int i=1;i<=n;i++){ if(n%i==0){ k=1-k; } } System.out.println(k); } } }
相关文章推荐
- iOS程序优化要点
- 学习Python,学习Pygame(四)
- IOSRadioGroup
- Ruby语言基础学习十一:Ruby异常 和综述
- PHP5.6通过CURL上传图片@符无效的兼容问题
- hdu 4146 Flip Game【思维+暴力】
- Linux内核创建一个新进程的过程
- fork和exec函数
- 获得同级iframe页面的指定ID元素的几种实现方法
- 深入理解letter-spacing和word-spacing2
- 空闲时间继续来学习!!!!!
- linux -grep用法
- 小黑的日常折腾-网段在线地址扫描shell脚本
- JavaScript之jQuery-7 jQuery 使用插件(使用插件、日历插件、表单验证插件)
- 最成功的失败学——《创游记:游戏团队创业成长之路》
- ACM常用的C++头文件!
- Java设计模式之单例模式
- Java并发编程系列之十一:synchronized(2)
- jvm(12)-java内存模型与线程
- [CodeVs1050]棋盘染色2(状态压缩DP)