博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1218 THE DRUNK JAILER
阅读量:7167 次
发布时间:2019-06-29

本文共 2005 字,大约阅读时间需要 6 分钟。

THE DRUNK JAILER
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 23358   Accepted: 14720

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 the number of prisoners that escape when the prison has n cells.

Sample Input

25100

Sample Output

210

Source

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespace std;15 int main() 16 { 17 int n,i,j,k,a,count,counter; 18 scanf("%d",&n); 19 for(i=1;i<=n;i++) 20 { 21 counter=0; 22 scanf("%d",&a); 23 for(k=1;k<=a;k++) 24 { 25 count=0; 26 for(j=1;j<=a;j++) 27 if(k%j==0) 28 count++;29 if(count%2!=0) 30 counter++;31 } 32 printf("%d\n",counter); 33 } 34 return 0;35 }
View Code

 

转载地址:http://cjmwm.baihongyu.com/

你可能感兴趣的文章
我的高质量软件发布心得
查看>>
DecimalFormat 类基本使用
查看>>
es6 Set和map数据结构
查看>>
数字键盘三
查看>>
12个值得关注的顶级JS库
查看>>
线程安全的CopyOnWriteArrayList介绍
查看>>
Java并发编程(一)Thread详解
查看>>
RealEvo 安装问题浅析
查看>>
Java并发核心-exchanger
查看>>
mysql数据迁移之<存储过程>
查看>>
5、前后端分离跨域问题
查看>>
spring结合mybatis不用手动关闭sqlSession 原理
查看>>
XSS攻击
查看>>
程序员如何做好应聘?简历、面试和Offer
查看>>
调试Linux内核操作指南(withing kgdb)
查看>>
LDA线性判别分析原理
查看>>
上海交通大学副教授何建平:网络系统中的数据隐私—量化、分析和设计
查看>>
数据库初探(二)
查看>>
docker离线安装
查看>>
CAD转换为图片可以设置哪些格式
查看>>