该题有题解
时间限制:1000MS 内存限制:65535K
提交次数:0 通过次数:0
题型: 编程题 语言: 无限制
Recently I read an interview problem. There are 100 lights, which are controled by buttons. There are 100 person. The 1st person turns on all the lights. The 2nd person, starts from the 2nd lights, and turns off the lights whose number is even. Then the 3rd person starts from the 3rd lights, switch the button of the lights whose number is the multiple of 3, namely turn on the light if the light is off or turn off the light if the turn off the light is on. Vice versa. When the 100th person switches the lights according to the rule, how many lights is on. It's an easy and ingenious problem. Now you should answer how many lights is on when there are X lights and X person according to the rule.
The first line input Case number T(T<=1000) Then T lines follow. Each line contains the integer number X(0<X<=100000000).
Ouput the number of lights which is on.
4 1 5 7 2
1 2 2 1
#include <iostream> #include <cmath> using namespace std; int main() { int T,n; cin>>T; while(T--) { cin>>n; cout<<(int)sqrt(n)<<endl; } return 0; }
AC后感:我也不知到这个规律是为什么,只是在撸的时候把n=1~16的结果列出来,发现了规律