Advertisement
totopopov

Special Number

Jul 21st, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Created by Todor Popov using Lenovo on 21.7.2017 г. at 19:30.
  5.  */
  6. public class SpecialNumber {
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.  
  12.         int m = Integer.parseInt(scanner.nextLine());
  13.         int n = Integer.parseInt(scanner.nextLine());
  14.         int l = Integer.parseInt(scanner.nextLine());
  15.  
  16.         int specialNumber = Integer.parseInt(scanner.nextLine());
  17.         int controlNumber = Integer.parseInt(scanner.nextLine());
  18.  
  19.         for (int i = m; i >= 1; i--) {
  20.             for (int j = n; j >= 1; j--) {
  21.                 for (int k = l; k >= 1; k--) {
  22.                    
  23.                     if ((i + j + k) % 3 == 0) {   // if the sum of the difits of a number % 3 ==0 then the number % 3==0 (math)
  24.                         specialNumber += 5;
  25.                     } else if (k == 5) {
  26.                         specialNumber -= 2;
  27.                     } else if (k % 2 == 0) {
  28.                         specialNumber *= 2;
  29.                     }
  30.  
  31.                     if (specialNumber >= controlNumber) {
  32.                         System.out.printf("Yes! Control number was reached! Current special number is %d.", specialNumber);
  33.                         return;
  34.                     }
  35.  
  36.  
  37.                 }
  38.             }
  39.         }
  40.  
  41.         System.out.printf("No! %d is the last reached special number.",specialNumber);
  42.  
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement