Skip to content

Instantly share code, notes, and snippets.

@staffordsmith83
Created August 19, 2020 12:08
Show Gist options
  • Save staffordsmith83/eac60d2e992ad511cb49d6c69be884e6 to your computer and use it in GitHub Desktop.
Save staffordsmith83/eac60d2e992ad511cb49d6c69be884e6 to your computer and use it in GitHub Desktop.
We have a block of chocolate with n * m dimensions (of pieces of chocolate!). This method determines if it is possible to break off exactly K segments from the chocolate with a single straight line: vertical or horizontal. The program gets an input of three integers: n, m, k.
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
int k = scanner.nextInt();
if (k > (n * m)) {
System.out.print("NO");
} else {
if (k % n == 0 && k >= n || k % m == 0 && k >= m) {
System.out.print("YES");
} else {
System.out.print("NO");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment