Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Bounce {
- public static final Scanner SC = new Scanner(System.in);
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] input = sc.nextLine().split(" ");
- int n = Integer.parseInt(input[0]);
- int m = Integer.parseInt(input[1]);
- long[][] matrix = new long[n][m];
- long sum = 0;
- for (int row = 0; row < n; row++) {
- for (int col = 0; col < m; col++) {
- matrix[row][col] = (long) Math.pow(2,row + col);
- }
- }
- for (int currentRow = 0; currentRow < n ; currentRow++) {
- if (currentRow % 2 == 0){
- for (int currentCol = 0; currentCol < m - 1; currentCol += 2) {
- if (currentRow != 0 && currentRow != n - 1){
- sum+= matrix[currentRow][currentCol];
- }
- sum += matrix[currentRow][currentCol];
- }
- }else {
- for (int currentCol = 1; currentCol < m; currentCol += 2) {
- if (currentCol != 0 && currentCol != m - 1){
- sum+= matrix[currentRow][currentCol];
- }
- sum += matrix[currentRow][currentCol];
- }
- }
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement