We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
sn=1+3+5+7+....
which is equal to sum of odd term series....
s1=(1*1)-(0-0)=1;
s2=(2*2)-(1*1)=3;
s3=(3*3)-(2*2)=5;
s4=(4*4)-(3*3)=7;
from above s1,s2,s3,s4 equations we can see that first term of first equation(s1) and second term of second equation(s2) gets cancelled,simillarly first term of second equation(s2) and second term of thid equation(s3) gets cancelled..and so on...
at last we remain with (4*4)-(0*0) i.e (n*n)-(0*0) i.e (n*n)
therefore... sn=n*n;
given in question that
sn%(10^9+7)
->(n*n)%(10^9+7)
we have a theorem which states that..
(a*b)%n=((a%n)*(b%n))%n
->(n*n)%(10^9+7)
->(n*n)%(1000000007)
frm above theorem..
->((n%1000000007)*(n%1000000007))%1000000007)
the above theorem helps us to clear test case 5 & 6
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Summing the N series
You are viewing a single comment's thread. Return to all comments →
sn=1+3+5+7+.... which is equal to sum of odd term series.... s1=(1*1)-(0-0)=1; s2=(2*2)-(1*1)=3; s3=(3*3)-(2*2)=5; s4=(4*4)-(3*3)=7; from above s1,s2,s3,s4 equations we can see that first term of first equation(s1) and second term of second equation(s2) gets cancelled,simillarly first term of second equation(s2) and second term of thid equation(s3) gets cancelled..and so on... at last we remain with (4*4)-(0*0) i.e (n*n)-(0*0) i.e (n*n) therefore... sn=n*n; given in question that sn%(10^9+7) ->(n*n)%(10^9+7) we have a theorem which states that.. (a*b)%n=((a%n)*(b%n))%n ->(n*n)%(10^9+7) ->(n*n)%(1000000007) frm above theorem.. ->((n%1000000007)*(n%1000000007))%1000000007) the above theorem helps us to clear test case 5 & 6