A - Switch Game

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

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.

题目描述:输入一个n,取i从1到n,在1~n中,是i的倍数,值就变一次,求最后变换完后第n个数的值。

No.1:查找含有多少因子

#include<iostream>
#include<algorithm>
using namespace std; int main() {
int n,ans;
while (cin >> n) {
ans = 2;
if (n <= 3)cout<<1<<endl;
else {
for (int i = 2; i*i<= n; i++) { //枚举含有几个因子
if (n%i == 0) {
if (i*i == n)ans++; //
else ans += 2; //如果不是i*i,那除了i是因子,n/i也是,所以上边枚举到i*i就可以了。
}
}
if (ans & 1)cout<<1<<endl;
else cout<<0<<endl;
}
}
return 0;
}

No.2:写博客时刚想到,可以直接判断n是不是某个整数的平方,是的话,因子肯定为奇数,所以结果为1.,不是结果为0

#include<iostream>
#include<algorithm>
using namespace std; int main() {
double n,ans;
while (cin >> n) {
int ans=0;
for(int i=1;i<400;i++){ //400*400就大于1e5了
if(i*i==n)ans=1;
}
if(ans)cout<<"1\n";
else cout<<"0\n";
}
return 0;
}

 

Switch Game :因子数的更多相关文章

  1. [Swift]LeetCode795. 区间子数组个数 | Number of Subarrays with Bounded Maximum

    We are given an array A of positive integers, and two positive integers L and R (L <= R). Return ...

  2. Partition:分区切换(Switch)

    在SQL Server中,对超级大表做数据归档,使用select和delete命令是十分耗费CPU时间和Disk空间的,SQL Server必须记录相应数量的事务日志,而使用switch操作归档分区表 ...

  3. java中if和switch哪个效率快

    首先要看一个问题,if 语句适用范围比较广,只要是 boolean 表达式都可以用 if 判断:而 switch 只能对基本类型进行数值比较.两者的可比性就仅限在两个基本类型比较的范围内.说到基本类型 ...

  4. [开源]QuickSwitchSVNClient,快速完成SVN Switch的工具

    在实际的开发中,我们一般使用SVN工具进行源代码的管理.在实际的产品开发中,根据项目的一些定制要求,往往需要对某一些代码的修改,但是又不想影响主要的开发,这个时候需要对当前的主分支做一些分支处理(br ...

  5. C#中,switch case语句中多个值匹配一个代码块的写法

    switch (num) { case 1: Response.Write("1"); break; case 2: case 3: Response.Write("2| ...

  6. Android Studio快捷键switch case 轻松转换为if else

    Android Studio快捷键switch case 轻松转换为if else 今天碰到的问题,没有找到资料,后面找到了方法,这个记下来,转载请注明出处:http://www.cnblogs.co ...

  7. 代码的坏味道(6)——Switch声明(Switch Statements)

    坏味道--Switch声明(Switch Statements) 特征 你有一个复杂的 switch 语句或 if 序列语句. 问题原因 面向对象程序的一个最明显特征就是:少用 switch  和 c ...

  8. java中的switch case

    switch-case语句格式如下 switch(变量){ case 变量值1: //; break; case 变量值2: //...; break; ... case default: //... ...

  9. switch语句的妙用

    switch语句的普通用法很简单,如下: var a = 3; switch (a) { case 1: console.log(a); break; case 2: case 3: console. ...

随机推荐

  1. nRF5 SDK for Mesh(二) Getting started 快速开始

    Getting started To get started, take a look at the Light switch demo. It shows how a simple applicat ...

  2. 字符型设备驱动程序-first-printf以及点亮LED灯(四)

    怎么样 把 写的 代码 和 编译 放到  开发板上 去执行? 2017年5月22日16:34:13 需要 自己 编译 Linux 内核.. 需要 以下 几个 条件: 1.正常运行 Linux 的 开发 ...

  3. 无法加载文件或程序集“Newtonsoft.Json”或它的某一个依赖项

    未能加载文件或程序集“Newtonsoft.Json”或它的某一个依赖项.找到的程序集清单定义与程序集引用不匹配. (异常来自 HRESULT:0x80131040). 有时候我们创建了一个类库,我们 ...

  4. 如何使用jquery.qrcode.js插件生成二维码

    1.首先需要准备 jquery.qrcode.js 和 jquery.js github地址:https://github.com/lrsjng/jquery-qrcode 官方文档地址:http:/ ...

  5. 并发编程(二)------并发类容器ConcurrentMap

    并发类容器: jdk5.0以后提供了多种并发类容器来替代同步类容器从而改善性能. 同步类容器的状态都是串行化的. 他们虽然实现了线程安全,但是严重降低了并发性,在多线程环境时,严重降低了应用程序的吞吐 ...

  6. misc类设备

    何为misc (1)中文名:杂项设备\杂散设备,它是一种典型的字符设,在一般情况下在内核中,所有的misc设备的主设备号是固定的,为10,它们的次设备号不一样:(2)可以在根文件系统中看到:/sys/ ...

  7. eclipse手动安装alibaba代码规范插件+取消阿里编码规约插件扫描出来的警告及错误

    如果你的开发环境无法访问外网,那么手动安装阿里巴巴的代码规范插件是一个不错的选择.另外,很多教程说该插件需要jdk1.8以上,我试了一下jdk1.7也是可以运行的,更低的版本就不知道了,貌似jdk1. ...

  8. golang总结-Redis整合

    目录 1. 基本用法 2. Redis连接池 go get github.com/gomodule/redigo/redis 1. 基本用法 获取连接 package conn import ( &q ...

  9. webpack4+Vue搭建自己的Vue-cli

    前言 最近在看webpack4,深感知识浅薄,这两天也一直在思考cli的配置,借助一些别人的实践,尝试自己搭建vue的项目,这里使用webpack4版本,之前我在网上查找别人的vue项目搭建,但是都是 ...

  10. mysql-5.7.24 在centos7安装

    搭建环境:mysql5.7.24  CentOS-7-x86_64-DVD-1804.iso  桌面版 1. 进入官网:https://dev.mysql.com/downloads/mysql/ 该 ...