
오일러 피
P[i] = P[i] - P[i]/i
GCD는 최대 공약수이다.
최대 공약수가 1이라는 것은 두 수 n, k 의 공약수가 1개라는 소리다. 즉 서로소 라는 뜻이다.
이 문제는 1부터 입력받은 값까지 중에서 서로소인 수를 구하는 문제이다.
Math.sqrt(key)까지 포문을 돌린다. for(long i =2; i<= Math.sqrt(key); i++)
if(count % i == 0){
result = result - result/i;
}
while(count % i == 0){
count /= i;
}
Math.sqrt(key)보다 큰 수일 경우를 대비 해서 다음 조건과 식을 추가한다.if( count>1 ){
result = result - result/count;
}
5.이후 결과값을 출력한다.
import java.io.*;
public class J11689_0 {
public static void main(String[] args) throws IOException {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
long key = Long.parseLong(buffer.readLine());
long count = key;
long result = key;
for(long i =2; i<= Math.sqrt(key); i++){
if(count % i == 0){
result = result - result/i;
while(count % i == 0){
count /= i;
}
}
}
if( count>1 ){
result = result - result/count;
}
System.out.println(result);
}
}