HDU 2051 Switch Game (analog/number theory)

Source: Internet
Author: User

Topic Meaning:

http://acm.hdu.edu.cn/showproblem.php?pid=2053

give you n a lamp, just start all out, ask after an infinite number of operations, the status of the nth lamp.


Topic Analysis:

See code comments.


AC Code:

/** * @xiaoran * should be a problem of number theory, first simulation look (over), now look at this problem * Test instructions: give you n lights, just start all out, ask after an infinite number of operations, the nth lamp state * For the first operation, change the status of multiples of all I * found when operation to n+ After 1 times, it certainly doesn't affect N, the problem becomes the state of n after the operation N Times * analyzed below: The state of the first n is 0, if the nth lamp operates an even number of times, its state is still 0, * operation Odd number of times to 1, now to analyze for N: If I is an approximate of n, it will change the state of N, but *j=n/  I is also an approximate number of N, will also change the state of N back, to here can be found when the i=n/i, will be * on the state of N is affected, just start n state is 0, if n is a complete square number, it will become 1. */#include <iostream> #include <cstdio> #include <map> #include <cstring> #include <string > #include <algorithm> #include <queue> #include <vector> #include <stack> #include < cstdlib> #include <cctype> #include <cmath> #define LL long longusing namespace Std;int a[100005];int Main (    ) {int n;        while (cin>>n) {int k= (int) (sqrt (n) +0.5);        k*k==n?printf ("1\n"):p rintf ("0\n");        /** Analogue memset (A,1,sizeof (a));            for (int. i=2;i<=n;i++) {for (int j=i;j<=n;j+=i) {a[j]=!a[j];        }} if (n==1) printf ("1\n");        else printf ("%d\n", A[n]); **/}return 0;} 


HDU 2051 Switch Game (analog/number theory)

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.