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.
defsum_calc(n):ifn==1:return1sum=1#1,3,5,7,9,13,17,21,25,31#for i in range(3,n+1,2):#sum+=(i**2)*4-6*(i-1)# it would be slower to do the above so I just compute it mathematically as a formula by the help of sum of first n squaresx=(n-1)//2sum+=(n*(n+1)*(2*n+1)//6-1-4*(x*(x+1)*(2*x+1)//6))*4-6*(x)*(x+1)returnsumfor_inrange(int(input())):n=int(input())print(sum_calc(n)%(10**9+7))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #28: Number spiral diagonals
You are viewing a single comment's thread. Return to all comments →
100/- points python3.
easy solve