https://www.acmicpc.net/problem/1437
1437번: 수 분해
첫째 줄에 음이 아닌 정수 N이 주어진다. N은 1,000,000보다 작거나 같다.
www.acmicpc.net


import java.io.*;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int max = 1;
if (n < 5)
max = n;
else {
if (n % 3 == 1) {
for (int i = 1; i < (n / 3) % 10007; i++) {
max *= 3;
max %= 10007;
}
max *= 4;
}
else if (n % 3 == 2) {
for (int i = 0; i < (n / 3) % 10007; i++) {
max *= 3;
max %= 10007;
}
max *= 2;
}
else
for (int i = 0; i < (n / 3) % 10007; i++) {
max *= 3;
max %= 10007;
}
max %= 10007;
}
System.out.println(max);
}
}

'baekjoon' 카테고리의 다른 글
| <java> 백준 1068 트리 (0) | 2022.10.01 |
|---|---|
| <java> 백준 14502 연구소 (1) | 2022.09.30 |
| <java> 백준 7569 토마토 (1) | 2022.09.30 |
| <java> 백준 7576 토마토 (0) | 2022.09.30 |
| <java> 백준 1897 토달기 (1) | 2022.09.30 |