Turn on the light
Time Limit: 3000 MS | memory limit: 65535 KB
Difficulty: 1
Description
There are n lamps numbered 1 ~ N, 1st people turn on all the lights, 2nd people press the switch in multiples of 2 (these lights will be turned off ), 3rd people press all the switches (the switched lights will be turned on, the lights will be turned off) numbered 3, and so forth. A total of K people asked which lights were on at last? Input: N and K, and output the number of lights on. K ≤ n ≤ 1000
Input
Enter a set of data: N and K
Output
Number of the lights on
Sample Input
7 3
Sample output
1 5 6 7
#include<iostream> #include<string.h> #include<stdio.h> #include<ctype.h> #include<algorithm> #include<stack> #include<queue> #include<set> #include<math.h> #include<vector> #include<map> #include<deque> #include<list> using namespace std; int main(){ int n,k,first=1; int a[1010]; memset(a,0,sizeof(a)); scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) { for(int m=1;m<=k;m++) { if(i%m==0) a[i]=a[i]+1; } } for(int y=1;y<=n;y++) { if(a[y]%2!=0) printf("%d ",y); } return 0;}
View code
Well, I am judging odd or even numbers.
There are many ways to judge ~