Geometric Progression Nth term

Find the nth term of G.P
first term of G.P is given....
Common ratio is also given...

CONSTRAINTS-
n<10^9
INPUT:
n=2
first term a=10
common ratio r=2

OUTPUT:
20

Output may be large so compute it modulo 10^9+7

I tried but for n>50 it gives TLE....
Last edited on
Then perhaps you should give up on this contest which is clearly beyond your abilities.
@dutch
i just want approach not a full code
Last edited on
i got it.....
ll square(ll n)
{
return n*n;
}
ll power(ll a,ll b,ll m)
{
if (b== 0)
return 1;
else if (b%2 == 0)
return square(bigmod(a,b/2,m)) % m; // square(x) = x * x
}
this code is giving correct answer upto 10^18....
Last edited on
Topic archived. No new replies allowed.