Created
January 14, 2015 14:33
-
-
Save mukulrawat1986/e8608d3d965999a2847e to your computer and use it in GitHub Desktop.
The re-factored fast solution to the project euler problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def func(n): | |
n1 = ((n/3) - 1) if n%3 == 0 else (n/3) | |
n2 = ((n/5) - 1) if n%5 == 0 else (n/5) | |
n3 = ((n/15)- 1) if n%15 == 0 else (n/15) | |
s1 = (n1*(n1+1))/2 | |
s2 = (n2*(n2+1))/2 | |
s3 = (n3*(n3+1))/2 | |
return (3*s1) + (5*s2) - (15*s3) | |
t = int(raw_input()) | |
while t>0: | |
n = int(raw_input()) | |
print func(n) | |
t-=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment