Wuhan University of Science and Technology acm:1008:0 starting point algorithm 58--the problem of open light

Source: Internet
Author: User

Problem Description

The computing Center has 8 computer rooms, each with n computers. Each computer has a number, such as the number of room 8th is H1 to HN, we sometimes called the H1 machine 1th, H2 for the number 2nd machine,...。
One day our school ranked among the top 100 universities in the world, and all the teachers and students had a carnival celebration. Mr. Luo is a very refreshing person, also like drinking, he drank a little more that day. But unfortunately, that night, Mr. Luo is on duty, teacher Luo is a very responsible teacher. So he opened the room number 8th. But the students are still partying, no one to get on the machine. Mr. Luo, carrying a bottle of wine, felt very bored, so he wanted to play a game.
In the first round, he drank a mouthful of wine, and he turned on all the computers. Then the second round he took a sip of wine, he put the number is 2,4,6,... Computer is all shut down. In the third round, he drank a drink and went to operate all the numbers are 3,6,9, ..., see the computer turned on and turn it off, see the computer turned off and turn it on. He repeats this operation for a total of n rounds. When he finished the last round, Mr. Luo fell drunk.
Now give you the number of computers in this computer room, ask you how many computers are open in the end?

Input

Multiple sets of data tests.

Input is only 1 lines, this line has a positive integer, indicating how many computers in this computer room, the number is any positive integer between 5 and 100.

Output

You must output the last number of computers that are open. Do not forget to change the line after outputting the number

Sample Input
5
Sample Output
2
HINT

for (i=1;i<=n;i++)//i represents the Turn 1--n

for (k=1;k<=n;k++)//k represents the computer number 1--n

My Code:

1#include <stdio.h>2 intMain ()3 {4     intn,i,j,x,sum,a[101];5      while(SCANF ("%d", &n)! =EOF)6     {7sum=0;8         if(n>=5&& n<= -)9         {Ten              for(i=1; i<=n;i++) One             { Aa[i]=1; -             }             -              for(i=2; i<=n;i++) the             { -                  for(j=1; j<=n;j++) -                 { -                     if(j%i==0) +                     { -                         if(a[j]==0) +                         { Aa[j]=1; at                         } -                         Else -                         { -a[j]=0; -                         } -                     } in                 } -             } to              for(i=1; i<=n;i++) +             { -                 if(a[i]==1) the                 { *sum++; $                 }Panax Notoginseng             }         -printf"%d\n", sum);  the         }         +     }     A     return 1; the}

Other code:

1#include <iostream>2 using namespacestd;3 4 intMain ()5 {6     intN,count;7     int*a =NULL;8      while(cin>>N)9     {TenCount=0; One         if(n> -|| n<5) A         { -             return 0; -         } theA =New int[n+1]; -          for(intI=0; i<=n;++i) -         { -a[i]=0; +         } -          for(intI=1; i<=n;++i) +         { A              for(intj=1; j<=n;++j) at             { -  -                 if(j%i==0) a[j]=1-A[j]; -             } -  -         } in          for(intI=1; i<=n;++i) -         { to             if(A[i]) +             { -++count; the             } *         } $cout<<count<<Endl;Panax Notoginseng     } -     return 0; the}

Wuhan University of Science and Technology acm:1008:0 starting point algorithm 58--Open the light problem

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.