Project Euler problem 2 pyhtonic solution (#629)

* Project Euler problem 2 pyhtonic solution

* Project Euler problem 2 made small changes
This commit is contained in:
Sanders Lin 2018-12-05 21:25:01 +08:00 committed by Libin Yang
parent dab312e0e7
commit 362270c19f
2 changed files with 4 additions and 8 deletions

View File

@ -18,9 +18,7 @@ i=1
j=2 j=2
sum=0 sum=0
while(j<=n): while(j<=n):
if((j&1)==0): #can also use (j%2==0) if j%2 == 0:
sum+=j sum+=j
temp=i i , j = j, i+j
i=j
j=temp+i
print(sum) print(sum)

View File

@ -12,9 +12,7 @@ a=0
b=2 b=2
count=0 count=0
while 4*b+a<n: while 4*b+a<n:
c=4*b+a a, b = b, 4*b+a
a=b count+= a
b=c
count=count+a
print(count+b) print(count+b)