(规律)poj - 1218 牛客OI赛制测试赛2 D-星光晚餐

THE DRUNK JAILER

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 29037   Accepted: 17926

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

2
5
100

Sample Output

2
10

Source

Greater New York 2002

[Submit]   [Go Back]   [Status]   [Discuss]

链接:https://www.nowcoder.com/acm/contest/185/D
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

Johnson和Nancy要在星光下吃晚餐。这是一件很浪漫的事情。

为了增加星光晚餐那浪漫的氛围,他拿出了一个神奇的魔法棒,并且可以按照一定的规则,改变天上星星的亮暗。

Johnson想考考Nancy,在他挥动魔法棒后,会有多少颗星星依旧闪耀在天空。他知道,Nancy一定会一口说出答案。

Nancy当然知道怎么做啦,但她想考考你!

Johnson先将天上n个星星排成一排,起初它们都是暗的。

他告诉他的妹子,他将挥动n次魔法棒,第i次挥动会将编号为i的正整数倍的星星的亮暗反转,即亮的星星转暗,暗的星星转亮。

Johnson想问Nancy,最终会有多少个星星依旧闪亮在天空。

输入描述:

一个整数n,含义请见题目描述。

输出描述:

一个整数ans,即n次操作后会有多少个星星依旧闪亮。

示例1

输入

复制

3

输出

复制

1

示例2

输入

复制

7

输出

复制

2

备注:

对于60%的数据:n≤2×106
对于100%的数据:n≤1018
#include<stdio.h>
#include<math.h>
int main(){
    long long n;
    scanf("%lld",&n);
    printf("%lld",(long long)sqrt(n*1.0));
    return 0;
}

猜你喜欢

转载自blog.csdn.net/black_horse2018/article/details/82500840
今日推荐