Hangzhou Electric 2053, easy to understand the C language code!!!

Source: Internet
Author: User

Re: Test instructions: There is an infinite number of lights in a row, at first it is closed, operation Infinite number of times, the first I operation will be numbered I and I in multiples of the electric light change the state. Ask the last I lamp status is open or off    //behind the data ...
#include <stdio.h>intMain(){intB,N,I; while(scanf("%d",&N)!=Eof) {if(N==1)//First operation, the switch is all changed to 1;Printf("1\n");Else {B=0; for(I=2;I<=N;I+ +)//starting from 2 to determine the approximate, switch starting from 1; {if(N%I==0)B++; }if(B%2==0)//Determine the number of switch changes, (1 0 1 0 1 0 ...);Printf("1\n");ElsePrintf("0\n"); } }return0;} 
Consider the second Test case:the initial condition:0 0 0 0 0 ... After the first Operation:1 1 1 1 1 ...   After the second Operation:1 0 1 0 1 ... After the third Operation:1 0 0 0 1 ...    After the fourth Operation:1 0 0 1 1 ... After the fifth Operation:1 0 0 1 0 ... The later operations cannot change the condition of the fifth lamp any more. So the answer is 0.

Hangzhou Electric 2053, easy to understand the C language code!!!

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.