서로 다른 세 정수 A, B, C가 주어질 때, A와 B를 0번 이상 더해서 만들 수 있는 C 이하의 수 중 최댓값을 구하는 문제.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
int B = sc.nextInt();
int C = sc.nextInt();
int loopA = C / A;
int loopB = C / B;
int max = 0;
for (int i = 0; i <= loopA; i++) {
for (int j = 0; j <= loopB; j++) {
if (A * i + B * j <= C)
max = Math.max(max, A * i + B * j);
}
}
System.out.println(max);
}
}
import java.util.Scanner;
public class Main {
public static int a, b, c;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
int ans = 0;
for(int i = 0; i * a <= c; i++) {
int cnt = a * i;
int numB = (c - cnt) / b;
cnt += numB * b;
ans = Math.max(ans, cnt);
}
System.out.print(ans);
}
}