fork download
  1. import java.util.Scanner;
  2.  
  3. class Main {
  4. public static void main (String[] args) {
  5. int counter = 1;
  6. Scanner in = new Scanner(System.in);
  7. int quantity = in.nextInt();
  8. int instrument = in.nextInt();
  9. if ((quantity == 6 && instrument != 1) || (quantity == instrument && quantity % 2 == 0)) {
  10. System.out.print(0);
  11. } else if (quantity == instrument) {
  12. for (int num = 1; num % quantity != 0; num += 6) {
  13. if (num != 1 && num % quantity == 1){
  14. System.out.print(0);
  15. System.exit(0);
  16. } else {
  17. counter++;
  18. }
  19. }
  20. System.out.print(counter);
  21. } else {
  22. for (int num = 1; num % quantity != instrument; num += 6) {
  23. if (num != 1 && num % quantity == 1) {
  24. System.out.print(0);
  25. System.exit(0);
  26. } else {
  27. counter++;
  28. }
  29. }
  30. System.out.print(counter);
  31. }
  32. }
  33. }
Success #stdin #stdout 0.1s 35468KB
stdin
13 13
stdout
3