Turn on the light for water questions

Source: Internet
Author: User

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 ~

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.