B - THE DRUNK JAILER POJ - 1218
2018-03-11 16:42
399 查看
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.InputThe 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.
OutputFor each line, you must print out the number of prisoners that escape when the prison has n cells.
Sample Input
开关问题;现在给你n个灯泡,要你操作n次,开始时灯泡都是关闭的,当进行第i次操作时,把第j个灯泡的状态
改变,j是i的倍数。问最后有多少个灯泡亮的。
对于任意数,在该题中,对于每个数,他又多少个因子就要操作多少次,只有当操作的次数为奇数时最后才是亮的。而只有当某数满足开平方后为整数时他的因子才为奇数,即求1到n中能开平方后为整数的个数,即sqrt(n)个
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.InputThe 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.
OutputFor each line, you must print out the number of prisoners that escape when the prison has n cells.
Sample Input
2 5 100Sample Output
210
开关问题;现在给你n个灯泡,要你操作n次,开始时灯泡都是关闭的,当进行第i次操作时,把第j个灯泡的状态
改变,j是i的倍数。问最后有多少个灯泡亮的。
对于任意数,在该题中,对于每个数,他又多少个因子就要操作多少次,只有当操作的次数为奇数时最后才是亮的。而只有当某数满足开平方后为整数时他的因子才为奇数,即求1到n中能开平方后为整数的个数,即sqrt(n)个
相关文章推荐
- POJ 1218 THE DRUNK JAILER
- poj 1218 THE DRUNK JAILER
- POJ 1218 THE DRUNK JAILER
- THE DRUNK JAILER - POJ 1218 水题
- THE DRUNK JAILER POJ 1218
- POJ 1218 THE DRUNK JAILER (题目虽然简单,但是学到了很多)
- POJ 1218 THE DRUNK JAILER
- POJ_1218_THE DRUNK JAILER
- poj 1218:THE DRUNK JAILER
- POJ 1218 THE DRUNK JAILER
- poj 1218 THE DRUNK JAILER
- POJ 1218 THE DRUNK JAILER
- POJ 1218 THE DRUNK JAILER 笔记
- POJ 1218 THE DRUNK JAILER【类开灯问题】
- THE DRUNK JAILER(POJ--1218
- POJ 1218 The Drunk Jailer
- 统计次数poj1218——THE DRUNK JAILER
- poj1218 THE DRUNK JAILER!
- poj 1218 THE DRUNK JAILER
- THE DRUNK JAILER POJ - 1218