题目描述
There are n lockers in a hallway numbered sequentially from 1 to n. Initially, all the locker doors are closed. You make n passes by the lockers, each time starting with locker #1. On the ith pass, i = 1, 2, ..., n, you toggle the door of every ith locker: if the door is closed, you open it, if it is open, you close it. For example, after the first pass every door is open; on the second pass you only toggle the even-numbered lockers (#2, #4, ...) so that after the second pass the even doors are closed and the odd ones are opened; the third time through you close the door of locker #3 (opened from the first pass), open the door of locker #6 (closed from the second pass), and so on. After the last pass, which locker doors are open and which are closed? How many of them are open? Your task is write a program to output How many doors are open after the last pass? Assumptions all doors are closed at first.
走廊里有n个储物柜,从1到n依次编号。最初,所有储物柜的门都是关闭的。你从储物柜经过n次,每次从1号储物柜开始。在第i遍时,i = 1,2,…例如,你拨动每一个储物柜的门:如果门是关着的,你就打开它,如果是开着的,你就关上它。例如,在第一次通过后,每扇门都是打开的;在第二次通过时,你只需要切换偶数号的储物柜(#2,#4,…),这样在第二次通过后偶数号的门就会关闭,奇数号的门就会打开;第三次你要关闭3号储物柜的门(在第一次通过时打开),打开6号储物柜的门(在第二次通过时关闭),以此类推。最后一关后,哪些储物柜门是开着的,哪些是关着的?有多少是开着的?你的任务是写一个程序输出在最后一关后有多少门是打开的?假设一开始所有的门都是关着的。
输入
a positive numbers n, total doors. n<=100000输出
a positive numbers ,the total of doors opened after the last pass.样例输入复制
10样例输出复制
3#include<bits/stdc++.h> #define ll long long #define int ll #define pii pair<int,int> #define mem(a,b) memset(a,b,sizeof(a)) #define endl '\n' #define N 100005 const int inf=0x3f3f3f3f; const double pi=acos(-1.0); using namespace std; signed main() { int n; cin>>n; int m=sqrt(n); cout<<m<<endl; return 0; }