Snippets Collections
import java.io.*;
import java.util.*;

class Solution
{
    
    public double termOfGP(int A,int B,int N)
    {
        // common ratio is given by r=b/a
        double r=(double)B/(double)A;
        // Nth term is given by a(r^(N-1))
        return (A*Math.pow(r,N-1)); 
    }

}

public class Main {
	public static void main (String[] args) {
	    
	    //taking input using Scanner class
		Scanner sc=new Scanner(System.in);
		
		//taking total testcases
		int T=sc.nextInt();
		while(T-->0)
		{
		    
		    Solution  obj=new Solution ();
		    int A,B;
		    
		    //taking A and B
		    A=sc.nextInt();
		    B=sc.nextInt();
		    int N;
		    
		    //taking N
		    N=sc.nextInt();
		    
		   //calling method termOfGP() of class GP
		   System.out.println((int)Math.floor(obj.termOfGP(A,B,N)));
		    
		}
		
	}
}
star

Sun Feb 06 2022 01:54:52 GMT+0000 (Coordinated Universal Time) https://practice.geeksforgeeks.org/problems/gp-term/1/?track=DSASP-Mathematics&batchId=190

#java #mathematics #gfg #geeksforgeeks #gpterm #geometricprogressionterm #geometricseries

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension