Sunday, March 6, 2016

Project Euler - Problem 2 - Sum of even Fibonaaci numbers

def euler2(n):

su = 0
lst = []
for i in xrange(1,n,3):
    if(i == 1):
        res = 2
    elif (i == 4):
        res = 8
    else:
        res = 4* lst[-1]+ lst[-2]


    if(res < n):
        lst.append(res)

    else:
        break


print sum(lst)

Count the Squares between any two numbers

import math

def get_squares(n1, n2): #Given n1, n2 are the numbers both inclusive

       print int(math.floor(math.sqrt(n2)) - math.ceil(math.sqrt(n1))) + 1