-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheuler001.py
28 lines (23 loc) · 850 Bytes
/
euler001.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
"""
def main():
# input number of test cases
t = int(raw_input().strip())
# for each case, compute the sum
for _ in range(t):
# input of n as a long integer to deal with big numbers
n = long(raw_input().strip())
# find the number of multiples within [0, n)
m3 = (n - 1) / 3
m5 = (n - 1) / 5
m15 = (n - 1) / 15
# compute directly the sum of these multiples
print (3 * m3 * (m3 + 1) + 5 * m5 * (m5 + 1) - 15 * m15 * (m15 + 1)) / 2
if __name__ == '__main__':
# print "This program is being run by itself"
main()
else:
print 'I am being imported from another module'