-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathEuler's Phi.java
More file actions
39 lines (37 loc) · 809 Bytes
/
Euler's Phi.java
File metadata and controls
39 lines (37 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;
import java.util.*;
class Main
{
//Sum of prime factors of a given number
static float euler(int n)
{
if(n == 1)
return 1 ;
for(int i = 2 ; i*i <= n ; i++)
{
if(n%i == 0)
{
return 1 ;
}
}
return (float)(n-1)/n ;
}
public static void main (String[] args)
{
int n ;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
float prod = n ;
for(int i = 1 ; i*i <= n ; i++)
{
if(i*i==n)
prod *= euler(i) ;
else if(n%i == 0)
{
prod *= euler(i) ;
prod *= euler(n/i) ;
}
}
System.out.print((int)prod*n/2);
}
}