import time
begin = 1
end = 1000000
start_time = time.time()
y = range(begin,end)
print( sum([i for i in y if (i%3) * (i%5)==0]) )
print("eukreign: %s seconds" % ( time.time() - start_time ) )
start_time = time.time()
y = range(begin,end)
def oneeul(a):
total = 0
for i in a:
if i%3 ==0 or i%5 ==0:
total += i
else :
total = total
return total
print( oneeul(y) )
print( "Blast: %s seconds" % ( time.time() - start_time ) )
start_time = time.time()
def arithmeticProgressionSum( start, finish, step ):
return ( ( start + finish ) * ( ( finish - start ) // step + 1 ) // 2 )
def geAndDivides( x, divisor ):
return ( ( ( x - 1 ) // divisor + 1 ) * divisor )
def leAndDivides( x, divisor ):
return ( x // divisor * divisor )
def sumOfDivisors( start, finish, divisor ):
return ( arithmeticProgressionSum( geAndDivides( start , divisor ),
leAndDivides( finish - 1, divisor ),
divisor ) )
def sumOfDivisors2( start, finish, divisor1, divisor2 ):
return ( sumOfDivisors ( start, finish, divisor1 ) +
sumOfDivisors ( start, finish, divisor2 ) -
sumOfDivisors ( start, finish, divisor1 * divisor2 ) )
print ( sumOfDivisors2( begin, end, 3, 5 ) )
print("Koala: %s seconds" % ( time.time() - start_time ) )
aW1wb3J0IHRpbWUKCmJlZ2luID0gMQplbmQgPSAxMDAwMDAwCgpzdGFydF90aW1lID0gdGltZS50aW1lKCkKeSA9IHJhbmdlKGJlZ2luLGVuZCkKcHJpbnQoIHN1bShbaSBmb3IgaSBpbiB5IGlmIChpJTMpICogKGklNSk9PTBdKSApCnByaW50KCJldWtyZWlnbjogJXMgc2Vjb25kcyIgJSAoIHRpbWUudGltZSgpIC0gc3RhcnRfdGltZSApICkKCnN0YXJ0X3RpbWUgPSB0aW1lLnRpbWUoKQp5ID0gcmFuZ2UoYmVnaW4sZW5kKQpkZWYgb25lZXVsKGEpOgogICAgdG90YWwgPSAwCiAgICBmb3IgaSBpbiBhOgogICAgCWlmIGklMyA9PTAgb3IgaSU1ID09MDoKICAgIAkJdG90YWwgKz0gaQogICAgCWVsc2UgOgogICAgCQl0b3Rh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