cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Geometric Progression Nth term
Geometric Progression Nth term
Jun 10, 2019 at 4:38pm UTC
cc046
(17)
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
Jun 10, 2019 at 4:41pm UTC
Jun 10, 2019 at 4:58pm UTC
dutch
(2548)
Then perhaps you should give up on this contest which is clearly beyond your abilities.
Jun 11, 2019 at 4:23am UTC
cc046
(17)
@dutch
i just want approach not a full code
Last edited on
Jun 11, 2019 at 4:53am UTC
Jun 11, 2019 at 4:52am UTC
cc046
(17)
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
Jun 11, 2019 at 4:53am UTC
Topic archived. No new replies allowed.