You are viewing a single comment's thread. Return to all comments →
//Using recursion
import java.util.*; import java.io.*; class Solution{ public static void main(String []argh){ Scanner in = new Scanner(System.in); int t=in.nextInt(); for(int i=0;i<t;i++){ int a = in.nextInt(); int b = in.nextInt(); int n = in.nextInt(); calculate(a, 0, a , b, n); } in.close(); } public static int calculate( int total, int s, int a, int b, int n) { if(s == n - 1) { System.out.println(total + ( (int)Math.pow( 2, s ) * b)); return total + ( (int)Math.pow(b, s )); } total += ( (int)Math.pow( 2, s ) * b); System.out.print(total + " "); s++; return calculate(total, s, a, b, n); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Loops II
You are viewing a single comment's thread. Return to all comments →
//Using recursion