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

Hinthint

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.

思路:

说下题目大意吧,

先把这些灯标上号,1 2 3 4 5 6 7 8 ……无穷

首先全是关的,也就是全是0

第一次操作 ,标号是1的倍数,全都变成相反的状态,也就是全变成1.。

第二次操作 ,标号是2的倍数,全都变成相反的状态,你可以看下,2 4 6……变成了0.。。

第三次操作 ,标号是3的倍数,全都变成相反的状态,你可以看下,3 6 9……

他问你 N 号台灯最后 变成了 什么状态,

例如 1号灯,最后变成了1,不管多少次操作都是1.。

例如 5号灯 最后变成了0,不管多少次操作都是0.。

当操作次数大于N的时候 N的状态就不会改变了,因为N不会是M(M>N)的倍数。。

本题思路很简单就是求n有几个约数(包括1和自身)如果有奇数个约数,变奇数次,结果也就是1;否则为0

import java.util.Scanner;

public class Main {
// static boolean[] islight = new boolean[100002]; public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt(); // for(int i=1;i<=n;i++){
// islight[i] = false;
// }
//
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= n; j++) {
// if(j%i==0){
// islight[j] = !islight[j];
// }
// }
// }
//
// if(islight[n]){
// System.out.println("1");
// }else{
// System.out.println("0");
// }
// 超时 int k =0;
for(int i=1;i<=n;i++){
if(n%i==0){
k++;
}
} if(k%2==0){
System.out.println("0");
}else{
System.out.println("1");
} } }
}

HDOJ 2053 Switch Game的更多相关文章

  1. hdu 2053 Switch Game 水题一枚,鉴定完毕

    Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. HDU 2053 Switch Game

    http://acm.hdu.edu.cn/showproblem.php?pid=2053 Problem Description There are many lamps in a line. A ...

  3. HDU 2053 Switch Game(开灯问题,完全平方数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2053 题目大意:灯开始是关着的,有n盏灯,i从1数到n每当灯的序号是i的倍数的时候就对灯进行一次操作( ...

  4. 杭电(hdu)2053 Switch Game 水题

    Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  5. 杭电oj2047-2049、2051-2053、2056、2058

    2047  阿牛的EOF牛肉串 #include<stdio.h> int main(){ int n,i; _int64 s[]; while(~scanf("%d" ...

  6. hdu 1039 (string process, fgets, scanf, neat utilization of switch clause) 分类: hdoj 2015-06-16 22:15 38人阅读 评论(0) 收藏

    (string process, fgets, scanf, neat utilization of switch clause) simple problem, simple code. #incl ...

  7. hdu 1035 (usage of sentinel, proper utilization of switch and goto to make code neat) 分类: hdoj 2015-06-16 12:33 28人阅读 评论(0) 收藏

    as Scott Meyers said in his book Effective STL, "My advice on choosing among the sorting algori ...

  8. hdu 1033 (bit masking, utilization of switch, '\0' as end of c string) 分类: hdoj 2015-06-15 21:47 37人阅读 评论(0) 收藏

    bit masking is very common on the lower level code. #include <cstdio> #include <algorithm&g ...

  9. hdoj:2053

    #include <iostream> #include <string> #include <vector> using namespace std; /* 无穷 ...

随机推荐

  1. ASP.NET MVC5框架揭秘 学习笔记01

    1.自治视图 在早期(作者也没说明是多早,自己猜吧),我们倾向于将所有与UI相关的操作糅合在一起(现在我身边还有很多人这样做),这些操作包括UI界面的呈现. 用户交互操作的捕捉与响应(UI处理逻辑). ...

  2. (转)PHP下编码转换函数mb_convert_encoding与iconv的使用说明

    之--http://www.jb51.net/article/21451.htm mb_convert_encoding这个函数是用来转换编码的.原来一直对程序编码这一概念不理解,不过现在好像有点开窍 ...

  3. C# 如何创建接口以及使用接口的简单Demo(转载!)

    //No:1  首先,我们要封装一个接口,接口中不要实现具体的方法(说白了这就是一个架子而已!) using System;using System.Collections.Generic;using ...

  4. iOS LaunchScreen设置启动图片,启动页停留时间

    [新建的iOS 项目启动画面默认为LaunchScreen.xib] 如果想实现一张图片作为启动页,如下图

  5. 实现Bootstrap Carousel Fade Transition 淡入淡出效果

    html代码: <div id="carousel" class="carousel slide carousel-fade" data-ride=&qu ...

  6. javascript基础学习(七)

    javascript之Object对象 学习要点: 创建Object对象 Object对象属性 Object对象方法 一.创建Object对象 new Object(); new Object(val ...

  7. 优秀Android开源项目

    开源项目汇总: Trinea/android-open-project · GitHub 包含个性化控件.工具库.优秀项目.开发及测试工具等 优秀完整项目: 1.Google I/O Android ...

  8. Linux的压缩解压命令快速上手——解压篇

    在Linux系统中,压缩文件通常是先将若干文件(包括目录)打包成一个tar文件,然后再调用压缩程序将tar文件压缩成相应的压缩包,这也就是为什么Linux系的压缩包的后缀通常都是像tar.gz,tar ...

  9. for语句嵌套使用 实现9*9乘法表

         这个实例主要考察对for循环语句的使用,出现递增规律的乘法表. 开发环境      开发工具:Microsoft Visual Studio2010 旗舰版 具体步骤      先是制作一个 ...

  10. 不定参数函数原理以及实现一个属于自己的printf函数

    一.不定参数函数原理 二.实现一个属于自己的printf函数 参考博文:王爽汇编语言综合研究-函数如何接收不定数量的参数