Turn on the light and turn off the light

Source: Internet
Author: User

Numbered1 ~ 100A lightbulb. At first, all the lights are out. Yes100When you press the light bulb, if the light is on, after you press the light switch, the light will go off. If the light is off, the light will be on after you press the switch.

Start to press the switch.

1st people put all the light bulb on and off once (according to the switch light Number:1, 2, 3,... 100).
2nd students, once every other lamp (by the switch lamp Number:2, 4, 6,..., 100).
3rd students, every two lights are pressed once (according to the switch lamp Number:3, 6, 9,..., 99).
......

The problem is that100How many lights are on after a classmate presses the button?

There is a mathematical solution to this problem. It can be seen that the bulb that has been pressed for an odd number of times should be on, and the bulb that has been pressed for an even number of times should be off. So what kind of bulb is pressed for an odd number of times? What kind of bulb is pressed for an even number again? From the press process, we can find that if the number of a bulb has an even number of factors, the bulb will be pressed for an even number, and vice versa. Now the question becomes, what kind of number has an odd number of factors, and what kind of number has an even number of factors? This involves a theorem called prime factor decomposition, which roughly means that any positive number can be uniquely expressed as the product of multiple prime factors.

For example:

14 = 2*7
50 = 2*5 ^ 2
...
100 = 2 ^ 2*5 ^ 2

That isN = (P [1] ^ e [1]) * (p [2] ^ e [2]) * ...... * (p [k] ^ e [k]), WhereP [I]Is the prime number,E [I]YesP [I]Power. By using this formula, we can export the formula for calculating the number of factors in a number:Factornumber (n) = (E [1] + 1) * (E [2] + 1) * ...... * (E [k] + 1).

under what conditions is the value of factornumber (n) an odd number? Obviously, all E [1], E [2],..., E [k] must be an even number to ensure that E [I] + 1 is an odd number, and the product of the result can be an odd number. Because E [1], E [2],..., E [k] is an even number, so n must be a full number of workers (because SQRT (N) = (P [1] ^ (E [1]/2) * (p [2] ^ (E [2]/2 ))*...... * (p [k] ^ (E [k]/2) is an integer ). Back to the lightbulb-by-lightbulb issue, 1 ~ 100, 81,100 10 , that is to say, only the lights numbered 10 are on.

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.