Problem:
Euler's Phi Function

For given integer n, count the totatives of n, that is, the positive integers less than or equal to n that are relatively prime to n.

Input

n

An integer n (1 ≤ n ≤ 1000000000).

Output

The number of totatives in a line.

Sample Input 1

6

Sample Output 1

2

Sample Input 2

1000000

Sample Output 2

400000

Solution in Python (judge verdict: Wrong Answer)

import math

def make_plist(n):
    sqrt = int(math.sqrt(n))
    plist = [1]*(sqrt+3)
    for i in range(2,int(math.sqrt(sqrt))+3):
        if plist[i]:
            plist[2*i::i] = [0 for x in range(2*i,sqrt+3,i)]
    return plist

def get_pfact(plist,n):
    pfact = []
    sqrt = int(math.sqrt(n))
    for i in range(2,sqrt+3):
        if plist[i] and n%i == 0:
            pfact.append(i)
    else:
        if len(pfact) == 0: pfact.append(n)
    return pfact

def get_phai(n,pfacts):
    phai = n
    for pfact in pfacts:
        phai *= (1-1/float(pfact))
    return int(phai)

# main
n = int(raw_input())
plist = make_plist(n)
pfacts = get_pfact(plist,n)
print get_phai(n,pfacts)