HDU1787 GCD Again "Euler function"

Source: Internet
Author: User

Topic Links:

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


Main topic:

give you an integer n, the number of integers with a range less than n, and an integer greater than 1 for the greatest common divisor of N.


Ideas:

The typical Euler function is deformed. The Euler function φ (n) is the number of greatest common divisor that is used to find an integer less than n, and N is 1.

So the answer to this question is ans = n-φ (n)-1.


AC Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace Std;int Euler (int n) {    int ret = n;    for (int i = 2; i*i <= n; ++i)    {        if (n = = = 0)        {            n/= i;            ret = ret-ret/i;        }        while (n% i = = 0)            n/= i;    }    if (n > 1)        ret = ret-ret/n;    return ret;} int main () {    int n;    while (~SCANF ("%d", &n) && N)    {        printf ("%d\n", N-euler (N)-1);    }    return 0;}


HDU1787 GCD Again "Euler function"

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.