Here you can find solutions for the famous Euler Project's Problems . Questions can find on following link https://www.hackerrank.com/contests/projecteuler/challenges.
Project Euler #1: Multiples of 3 and 5 :
# Enter your code here. Read input from STDIN. Print output to STDOUT
t= input()
for i in range(0,t):
no=input()
n=(no-1)/3
sum_3=(n*(2*3+3*(n-1))/2)
n=(no-1)/5
sum_5=(n*(2*5+5*(n-1))/2)
n=(no-1)/15
sum_15=(n*(2*15+15*(n-1))/2)
print sum_3+sum_5-sum_15
Project Euler #1: Multiples of 3 and 5 :
# Enter your code here. Read input from STDIN. Print output to STDOUT
t= input()
for i in range(0,t):
no=input()
n=(no-1)/3
sum_3=(n*(2*3+3*(n-1))/2)
n=(no-1)/5
sum_5=(n*(2*5+5*(n-1))/2)
n=(no-1)/15
sum_15=(n*(2*15+15*(n-1))/2)
print sum_3+sum_5-sum_15
No comments:
Post a Comment