Poj (2407), Greater New York regional (D)

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=2407

Relatives
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 13599 Accepted: 6772

Description

Given N, a positive integer, how many positive integers less than n is relatively prime to n? Integers A and B are relatively prime if there is no integers x > 1, y > 0, z > 0 such that a = XY and B = x Z.

Input

There is several test cases. For the test case, the standard input contains a line with n <= 1,000,000,000. A line containing 0 follows.

Output

For all test case there should is single line of output answering the question posed above.

Sample Input

7120

Sample Output

64

Source

Waterloo local 2002.07.01 Two questions similar to the idea of the knot, are to find a number of coprime number. With Euler functions. Euler function: A factor of the number x P1,p2,p3,......, then his Euler function is X (1-1/P1) (1-1/P2) (1-1/P3) ...
The Euler function is equivalent to a filter, and when a factor factor is found, it is all out of the element. Then Greater New York Regional (D), 1 is a special case, he has the number of 0/1,1/1 two coprime, so ans[1] = 2; then you can hit the table again.
#include <stdio.h>intEuler (intN) {    intAns =N;  for(intI=2; i*i<=n;i++)    {        if(n%i==0) {n/=i; Ans= ans-ans/i;  while(n%i==0) {n/=i; }        }    }    if(n>1) ans = ans-ans/N; returnans;}intMain () {intN;  while(SCANF ("%d",&N) {printf ("%d\n", Euler (n)); }    return 0;}
View Code
#include <stdio.h>intEuler (intN) {    intres =N;  for(intI=2; i*i<=n; i++)    {        if(n%i==0) {n=n/i; Res= res-res/i;  while(n%i==0) n/=i; }    }    if(n>1) res = res-res/N; returnRes;}intMain () {intcases; scanf ("%d",&cases); intans[10005]; ans[1] =2;  for(intI=2; i<=10000; i++) {Ans[i]=ans[i-1]+Euler (i); }     while(cases--)    {        intt,k; scanf ("%d%d",&t,&k); printf ("%d%d\n", T,ans[k]); }    return 0;}
View Code

Poj (2407), Greater New York regional (D)

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.