Hdoj 1787 GCD Again "Euler function"

Source: Internet
Author: User
Tags greatest common divisor

GCD Again

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2673 Accepted Submission (s): 1123


Problem Descriptiondo you had spent some time to think and try to solve those unsolved problem after one ACM contest?
No? Oh, you must does this if you want to become a "Big cattle".
Now you'll find the This problem are so familiar:
The greatest common divisor GCD (A, b) of both positive integers a and B, sometimes written (a, b), is the largest divisor Common to A and B. For example, (1, 2) = 1, (12, 18) =6. (A, B) can is easily found by the Euclidean algorithm. Now I am considering a little more difficult problem:
Given An integer N, please count the number of the integers M (0<m<n) which satisfies (n,m) >1.
This was a simple version of the problem "GCD" which you had done with a contest RECENTLY,SO I name This problem "GCD Again". If you cannot solve it still,please take a good think about your method of study.
Good luck!

Inputinput contains multiple test cases. Each test case is contains an integers N (1<n<100000000). A test case containing 0 terminates, the input and this test are not processed.

Outputfor each integers N-should output the number of integers M in one line, and with one line of output for each Lin E in input.

Sample Input240

Sample Output01 Test Instructions: The number of 2 to n-1 and N does not coprime, because the Euler function is calculated with n coprime number of numbers so with N-el (n) can be, because more than one so also minus 1
#include <stdio.h> #include <string.h>int el (int n) {int i;int ans=n;for (i=2;i*i<=n;i++)//i*i for increased computational efficiency {                   if (n%i==0)    ans=ans/i* (i-1), while (n%i==0)    n/=i;} if (n>1)//In order to avoid a situation where there is no operation to 1     ans=ans/n* (n-1); return ans;} int main () {int n,m,j,i;while (scanf ("%d", &m), m) {printf ("%d\n", M-el (m)-1);} return 0;}

  

Hdoj 1787 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.