Switch Game :因子数
A - Switch Game
Problem Description
Input
Output
Sample Input
Sample Output
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 :因子数的更多相关文章
- [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 ...
- Partition:分区切换(Switch)
在SQL Server中,对超级大表做数据归档,使用select和delete命令是十分耗费CPU时间和Disk空间的,SQL Server必须记录相应数量的事务日志,而使用switch操作归档分区表 ...
- java中if和switch哪个效率快
首先要看一个问题,if 语句适用范围比较广,只要是 boolean 表达式都可以用 if 判断:而 switch 只能对基本类型进行数值比较.两者的可比性就仅限在两个基本类型比较的范围内.说到基本类型 ...
- [开源]QuickSwitchSVNClient,快速完成SVN Switch的工具
在实际的开发中,我们一般使用SVN工具进行源代码的管理.在实际的产品开发中,根据项目的一些定制要求,往往需要对某一些代码的修改,但是又不想影响主要的开发,这个时候需要对当前的主分支做一些分支处理(br ...
- C#中,switch case语句中多个值匹配一个代码块的写法
switch (num) { case 1: Response.Write("1"); break; case 2: case 3: Response.Write("2| ...
- Android Studio快捷键switch case 轻松转换为if else
Android Studio快捷键switch case 轻松转换为if else 今天碰到的问题,没有找到资料,后面找到了方法,这个记下来,转载请注明出处:http://www.cnblogs.co ...
- 代码的坏味道(6)——Switch声明(Switch Statements)
坏味道--Switch声明(Switch Statements) 特征 你有一个复杂的 switch 语句或 if 序列语句. 问题原因 面向对象程序的一个最明显特征就是:少用 switch 和 c ...
- java中的switch case
switch-case语句格式如下 switch(变量){ case 变量值1: //; break; case 变量值2: //...; break; ... case default: //... ...
- switch语句的妙用
switch语句的普通用法很简单,如下: var a = 3; switch (a) { case 1: console.log(a); break; case 2: case 3: console. ...
随机推荐
- 系统构架篇之基于SSDB的二级缓存
1.什么是ssdb 你可以把ssdb理解成redis.不同之处在于redis缓存的数据是在内存中的,所能缓存的数据大小受内存大小的限制,一般不适合缓存大量的数据.而ssdb将数据保存在磁盘中,数据量大 ...
- Linux下安装pip无法使用的情况
不知道有没有安装成功,首先先卸载软件 sudo apt-get purge --auto-remove python3-pip sudo apt-get update 然后在重新安装 sudo apt ...
- iOS:Masonry约束经验(19-03-21更)
1.label约束: 1).只需约束x.y 点相关就行.宽高 长度相关不用约束,就算用boundingRectWithSize计算出来的,也可能不准. 如:top.bottom二选一,trailing ...
- Autolayout中Hugging和Compression使用注意
前言 本文主要侧重Autolayout使用过程中,通过代码和SB添加含有intrinsicSize属性控件约束的一些细节. 来自我的博客,欢迎访问:To Be Independent. Hugging ...
- Python - 入门基础(一)
1.解释器路径 #!/usr/bin/env python 2.编码 # -*- coding:utf8 -*- 1.ascill ---00000000 (8个位表示) 缺点:表示不了英文 2.u ...
- python获取网页编码问题(encoding和apparent_encoding)
在requests获取网页的编码格式时,有两种方式,而结果也不同,通常用apparent_encoding更合适 注:推荐一个大佬写的关于获取网页编码格式以及requests中text()和conte ...
- [Golang学习笔记] 03 库源码文件
库源码文件:不能被直接运行的源码文件,它仅用于存放程序实体,这些程序实体可以被其他代码使用. 代码包声明的基本规则: 1. 同目录下的源码文件的代码包声明语句要一致.也就是说,它们要同属于一个代码包( ...
- spark执行命令 监控执行命令
#!/bin/bash #/usr/hdp/current/flume-server/bin/flume-ng agent -c conf/ -f /usr/hdp/current/flume-ser ...
- NodeJS设置Header解决跨域问题
转载: NodeJS设置Header解决跨域问题 app.all('*', function (req, res, next) { res.header('Access-Control-Allow-O ...
- browser storage limation
http://www.html5rocks.com/en/tutorials/offline/quota-research/?redirect_from_locale=zh