xynuoj1702-to find new friends

Source: Internet
Author: User
Tags greatest common divisor time limit
1702: Find new friendsTime limit: 1 Sec memory limit: MB
Submissions: 16 Resolution: 7
The status of your title: Completed
Submitted State [Discussion Version] Title DescriptionThe new year is coming, Tian Qin ready to engage in a party, already know the existing member N, the member from 1 to n number, where the president's number is N, and the president is an old friend, then the member's number and N has more than 1 of the convention number, otherwise are new friends, now the president wants to know how many new friends. Please make up the program gang length calculation. inputThe first line is the number of groups of test data cn (case number,1<cn<10000), followed by a CN-line positive integer n (1<n<32768), representing the number of members. OutputFor each n, the number of new friends is output, so there is a CN line output. Sample Input
2
25608
24027
Sample Output
7680
16016

The Euler function can be used to calculate the number of (1~n-1) between the numbers and N coprime (that is, greatest common divisor is 1), the following code

 #include <stdio.h> int T, n;
    Euler function 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 main () {//Freopen ("Input.txt", "R", stdin);
    scanf ("%d", &t);
        while (t--) {scanf ("%d", &n);
    The number of n-1 before solving is as many as N coprime printf ("%d\n", Eular (n));
} return 0; }

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.