HDU 1286 Find new friends (Euler function template)

Source: Internet
Author: User
Tags functions

HDU 1286 Find a new friend: http://acm.hdu.edu.cn/showproblem.php?pid=1286

Question: Chinese problem.

Idea: The pure template problem of Euler function, there is nothing to say, it is mainly to understand the meaning of Euler function.

In number theory, for positive integers n, Euler functions are less than or equal to n number of numbers with n coprime. This function, named after its first researcher Euler, is also known as the Euler ' s totient function, φ functions, Euler quotient, and so on.   For example φ (8) = 4, because 1,3,5,7 and 8 coprime. ----by degrees Niang.

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

#include <stdio.h>
   
int eular (int n) {
    int ret = 1;
    for (int i = 2; i*i <= n;i++)
        if (n%i = = 0) {
            n/= i, ret *= i-1;
            while (n%i = = 0)
                n/= i, ret *= i;
        }
    if (n > 1)
        ret *= n-1;
    return ret;
}
   
int T, n;
   
int main ()
{
    scanf ("%d", &t);
    while (t--)
    {
        scanf ("%d", &n);
        printf ("%d\n", Eular (n));
    }
   
    return 0;
}
   
HDU 1286

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.