Ultraviolet A 10110-light, more light

Source: Internet
Author: User

A person is responsible for switching bulbs in the corridor. There are n bulbs (numbered from 1 to n) in the corridor, and he will go back and forth to N;

At the beginning of the I-th step, he will switch the light bulb whose number can be divisible by I;

Now we need to figure out whether the last light bulb (number N) is bright or dark after N trips.

Analysis: mathematics. This question is the parity of the number of N factors.

If X | N, N/X | n is displayed in pairs;

Here is a special case. If n is the total number of workers, SQRT (n) only appears once;

Therefore, if n is the number of complete integers, the factor is an odd number. Otherwise, the factor is an even number.

Note: int cannot be stored (⊙ _ ⊙ ).

#include <iostream>#include <cstdlib>#include <cmath>using namespace std;int main(){long long n;while (cin >> n && n) {long long v = (int)sqrt(n+0.0);if (v*v == n)cout << "yes" << endl;else cout << "no" << endl;}return 0;}


Ultraviolet A 10110-light, more light

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.