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

  1. Consider the second test case
  2. The initial condition : 0 0 0 0 0
  3. After the first operation : 1 1 1 1 1
  4. After the second operation : 1 0 1 0 1
  5. After the third operation : 1 0 0 0 1
  6. After the fourth operation : 1 0 0 1 1
  7. After the fifth operation : 1 0 0 1 0
  8. 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:查找含有多少因子

  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n,ans;
  7. while (cin >> n) {
  8. ans = 2;
  9. if (n <= 3)cout<<1<<endl;
  10. else {
  11. for (int i = 2; i*i<= n; i++) { //枚举含有几个因子
  12. if (n%i == 0) {
  13. if (i*i == n)ans++; //
  14. else ans += 2; //如果不是i*i,那除了i是因子,n/i也是,所以上边枚举到i*i就可以了。
  15. }
  16. }
  17. if (ans & 1)cout<<1<<endl;
  18. else cout<<0<<endl;
  19. }
  20. }
  21. return 0;
  22. }

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

  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. double n,ans;
  7. while (cin >> n) {
  8. int ans=0;
  9. for(int i=1;i<400;i++){ //400*400就大于1e5了
  10. if(i*i==n)ans=1;
  11. }
  12. if(ans)cout<<"1\n";
  13. else cout<<"0\n";
  14. }
  15. return 0;
  16. }
  1.  
 

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. i2c 通信

    时间长了记忆就会模糊, 保存下逻辑分析抓到的图像, 什么时候需要可以看一眼. 当clk处于高电平时, data线有下降,说明开始传输, 有上升说明结束传输. 发送地址无回应: 发送地址有回应 正常数据 ...

  2. 部分用户间接性访问不了linux服务器解决方法

    linux的/etc/sysctl.conf中应设置 net.ipv4.tcp_tw_reuse = net.ipv4.tcp_tw_recycle = 参考文章: https://ieevee.co ...

  3. Java中的监听器

    servlet的技术规范包括三个:servlet,listener,filter,今天记录一下listener的学习. 监听器就是监听某个对象的状态变化的技术.监听器包括事件源,监听器,注册监听器以及 ...

  4. Java中 方法的多态 简析图

    代码如下: public class Client{    public static void main(String[] args){        Person p = new Person() ...

  5. vue中使用swiper并自定义分页器样式

    一,安装swiper 执行命令 npm install vue-awesome-swiper --save 二,引入swiper import {Swiper} from "vue-awes ...

  6. ueditor getshell漏洞重现及分析

    0x00 概述 8月21日,网上爆出ueditor .net版本getshell漏洞,由于只校验ContentType而没校验文件后缀导致getshell. 0x01 漏洞重现 Payload: &l ...

  7. javascript设计模式系列二-封装

    JavaScript封装: var Book = function (id, name, price) { this.id = id, this.name = name, this.price = p ...

  8. c3p0封装

    配置文件 <?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <defaul ...

  9. Redis数据库 : 基础

    设置密码: /etc/redis/redis.conf 文件把 requirepass 取消注释并设置密码 取消只能本地登录的bind 同上面的配置文件 把 bind一行注释掉 带密码登录: redi ...

  10. [译]C语言实现一个简易的Hash table(2)

    上一章,简单介绍了Hash Table,并提出了本教程中要实现的几个Hash Table的方法,有search(a, k).insert(a, k, v)和delete(a, k),本章将介绍Hash ...