Java Loops II

  • + 0 comments

    You don't need Math.pow. It's slower than it needs to be. Can be done with a simple (2*multiplier+1) update per loop:

    import java.util.*;
    import java.io.*;
    
    class Solution{
        public static void main(String []argh){
            Scanner in = new Scanner(System.in);
            int t=in.nextInt(); //number of queries
            
            for(int i=0;i<t;i++){
                int a = in.nextInt();
                int b = in.nextInt();
                int n = in.nextInt(); //number of iterations
                
                int multiplier = 0;
                
                for (int j = 0 ; j <  n ; j++){
                    multiplier = 2*multiplier+1;
                
                    System.out.print(a + b*(multiplier) + " ");
                }
                System.out.print("\n");
            }
                    
            in.close();
        }
    }