You are viewing a single comment's thread. Return to all comments →
Thank You. I have used the shift operation as you said but two test cases failed out of 5. Could you please help me with this code?
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(); int first = a+b; int sec = (2*b)+first; System.out.print(first+" "+sec+" "); int sum = sec; for(int j=1;j<=n-2;j++){ int s = ((2<<j)*b); sum = sum + s; System.out.print(sum+" "); } System.out.println(" "); } in.close(); } }
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 →
Thank You. I have used the shift operation as you said but two test cases failed out of 5. Could you please help me with this code?