Java Loops II

  • + 0 comments

    import java.util.*;

    class Solution { public static void main(String[] argh) { Scanner in = new Scanner(System.in);

        int t = in.nextInt(); // Number of test cases
    
        for (int i = 0; i < t; i++) {
            int a = in.nextInt(); // Base value
            int b = in.nextInt(); // Multiplier
            int n = in.nextInt(); // Number of terms
    
            int result = a;
            int power = 1; // Start with 2^0 = 1
    
            for (int j = 0; j < n; j++) {
                result += power * b;
                System.out.print(result + " ");
                power *= 2; // Next power of 2
            }
    
            System.out.println(); // Move to next line after each test case
        }
    
        in.close(); // Close the scanner
    }
    

    }