Advertisement
AngelGiurov

Untitled

Jul 18th, 2021
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Bounce {
  4. public static final Scanner SC = new Scanner(System.in);
  5.  
  6. public static void main(String[] args) {
  7. Scanner sc = new Scanner(System.in);
  8. String[] input = sc.nextLine().split(" ");
  9. int n = Integer.parseInt(input[0]);
  10. int m = Integer.parseInt(input[1]);
  11. long[][] matrix = new long[n][m];
  12. long sum = 0;
  13. for (int row = 0; row < n; row++) {
  14. for (int col = 0; col < m; col++) {
  15. matrix[row][col] = (long) Math.pow(2,row + col);
  16. }
  17. }
  18. for (int currentRow = 0; currentRow < n ; currentRow++) {
  19. if (currentRow % 2 == 0){
  20.  
  21. for (int currentCol = 0; currentCol < m - 1; currentCol += 2) {
  22. if (currentRow != 0 && currentRow != n - 1){
  23. sum+= matrix[currentRow][currentCol];
  24. }
  25. sum += matrix[currentRow][currentCol];
  26. }
  27. }else {
  28.  
  29. for (int currentCol = 1; currentCol < m; currentCol += 2) {
  30. if (currentCol != 0 && currentCol != m - 1){
  31. sum+= matrix[currentRow][currentCol];
  32. }
  33. sum += matrix[currentRow][currentCol];
  34. }
  35. }
  36. }
  37. System.out.println(sum);
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement