fork download
  1. import time
  2.  
  3. begin = 1
  4. end = 1000000
  5.  
  6. start_time = time.time()
  7. y = range(begin,end)
  8. print( sum([i for i in y if (i%3) * (i%5)==0]) )
  9. print("eukreign: %s seconds" % ( time.time() - start_time ) )
  10.  
  11. start_time = time.time()
  12. y = range(begin,end)
  13. def oneeul(a):
  14. total = 0
  15. for i in a:
  16. if i%3 ==0 or i%5 ==0:
  17. total += i
  18. else :
  19. total = total
  20. return total
  21. print( oneeul(y) )
  22. print( "Blast: %s seconds" % ( time.time() - start_time ) )
  23.  
  24. start_time = time.time()
  25. def arithmeticProgressionSum( start, finish, step ):
  26. return ( ( start + finish ) * ( ( finish - start ) // step + 1 ) // 2 )
  27.  
  28. def geAndDivides( x, divisor ):
  29. return ( ( ( x - 1 ) // divisor + 1 ) * divisor )
  30.  
  31. def leAndDivides( x, divisor ):
  32. return ( x // divisor * divisor )
  33.  
  34. def sumOfDivisors( start, finish, divisor ):
  35. return ( arithmeticProgressionSum( geAndDivides( start , divisor ),
  36. leAndDivides( finish - 1, divisor ),
  37. divisor ) )
  38.  
  39. def sumOfDivisors2( start, finish, divisor1, divisor2 ):
  40. return ( sumOfDivisors ( start, finish, divisor1 ) +
  41. sumOfDivisors ( start, finish, divisor2 ) -
  42. sumOfDivisors ( start, finish, divisor1 * divisor2 ) )
  43.  
  44. print ( sumOfDivisors2( begin, end, 3, 5 ) )
  45. print("Koala: %s seconds" % ( time.time() - start_time ) )
  46.  
Success #stdin #stdout 0.9s 9344KB
stdin
Standard input is empty
stdout
233333166668
eukreign: 0.46097397804260254 seconds
233333166668
Blast: 0.4050259590148926 seconds
233333166668
Koala: 2.002716064453125e-05 seconds