Pku1218
<span style="background-color: rgb(204, 204, 204);">/*
A - THE DRUNK JAILER
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
Submit Status Practice POJ 1218
Description
A certain prison contains a long hall of n cells, each right next to each other. Each cell has a prisoner in it, and each cell is locked.
One night, the jailer gets bored and decides to play a game. For round 1 of the game, he takes a drink of whiskey,and then runs down the hall unlocking each cell. For round 2, he takes a drink of whiskey, and then runs down the
hall locking every other cell (cells 2, 4, 6, ?). For round 3, he takes a drink of whiskey, and then runs down the hall. He visits every third cell (cells 3, 6, 9, ?). If the cell is locked, he unlocks it; if it is unlocked, he locks it. He
repeats this for n rounds, takes a final drink, and passes out.
Some number of prisoners, possibly zero, realizes that their cells are unlocked and the jailer is incapacitated. They immediately escape.
Given the number of cells, determine how many prisoners escape jail.
Input
The first line of input contains a single positive integer. This is the number of lines that follow. Each of the following lines contains a single integer between 5 and 100, inclusive, which is the number of cells n.
Output
For each line, you must print out <span style="color:#6633ff;">the</span> number of prisoners that escape when the prison has n cells.
Sample Input
2
5
100
Sample Output
2
10
By Grant Yuan
2014.7.11
*/
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
bool a[101];
int main()
{int m,n,i,j,sum=0;
cin>>n;
while(n--){memset(a,0,101);
cin>>m;
for(i=1;i<=m;i++)
for(j=1;j<=m;j++)
if(j%i==0) a[j]=1-a[j];
for(j=1;j<=m;j++)
if(a[j]) sum++;
cout<<sum<<endl;
sum=0;
}
return 0; }
</span>
Pku1218的更多相关文章
随机推荐
- Nancy 框架学习
Nancy 框架 1.是一个轻量级用于构建http相应的web框架: 2.与mvc类似,有自己的路由机制: 3.可以处理 DELETE , GET , HEAD , OPTIONS , POS ...
- 淘宝API学习之道:淘宝API相关了解
淘宝API开发平台,经过两年多的升级一系列动作,提供的api接口日渐稳定.看到淘宝api开发的浏览量还是较大,但那会写的DEMO如今已不能执行,淘宝改了链接地址,改了加密算法,为了不让大家浪费时间,特 ...
- html 块状元素 行内元素 内联元素
块状(Block)类型的元素的width默认为100%,而行内(Inline)类型的元素则是根据自身的内容及子元素来决定宽度. 块元素(block element) address - 地址 bloc ...
- 【C++基金会 04】vector详细解释
根据写博客开始总有一些事情的习惯,加鸡汤文,今天请原谅我记得. ============================================= 今天要写的内容是顺序型容器.首先,标准库定义 ...
- Team Foundation Server 2015使用教程--默认团队权限说明
- c#左右socket连接超时控制方案
之前有一个项目中使用Remoting技术.当远程地址无效或server不执行,访问远程对象的方法,它会经过几十秒的时间来抛出异常秒. 由于我使用tcp状态.因此,认为可以使用socket为了测试连接, ...
- Java多线程中wait, notify and notifyAll的使用
本文为翻译文章,原文地址:http://www.journaldev.com/1037/java-thread-wait-notify-and-notifyall-example 在Java的Obje ...
- 活锁(livelock)
活锁(livelock) 活锁指的是任务或者执行者没有被阻塞,由于某些条件没有满足,导致一直重复尝试,失败,尝试,失败. 活锁和死锁的区别在于,处于活锁的实体是在不断的改变状态,所谓的“活”, 而处于 ...
- 2014年辛星Javascript解读第四节 流程控制语句
上一节我们介绍了函数,本小节我们介绍一下流程控制语句,对于不论什么一门编程语言来说,流程控制都是很重要的,也就是我们常说的顺序结构.选择结构和循环结构. ************选择结构******* ...
- hdu 4864 Task---2014 Multi-University Training Contest 1
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 Task Time Limit: 4000/2000 MS (Java/Others) M ...