코딩테스트 조지러 함 가보자 ~
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int count = 0;
while (true) {
if (N % 5 ==0) {
count += (N / 5);
break;
} else {
N -= 3;
count++;
}
if (N < 0) {
count = -1;
break;
}
}
System.out.println(count);
}
}
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int count = 0;
while (n > 2) {
if (n % 5 != 0) {
n -= 3;
count++;
if (n % 5 %% n % 3 != 0) { // 5와 3으로 나누어 떨어지지 않으면
count = -1;
n = count;
}
} else {
count += n / 5;
break;
}
}
System.out.println(count);
}
}
참조