Categories
Project Euler

Even Fibonacci numbers – Problem2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

program language (python)
In Python :

suma,sumaPre,konačanSuma = 3,2,0

while(sumaPre<4000000):
suma+=sumaPre
sumaPre=suma-sumaPre
if suma % 2 == 0:
konačanSuma+=suma

print (konačanSuma + 2)

second problem is done 🙂 .

problem 3

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

thank you for watching.

Categories
Project Euler

Multiples of 3 and 5 Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples.

program language (c++,python)
in c++:

int zbir = 0;
int b = 8456;
int i;
int m;
int n;
void setup() {
// put your setup code here, to run onc
Serial.begin(115200);
}

void loop() {
// put your main code here, to run repeatedly:
long suma=0;
Serial.println (i);
for (i =0;i<b;i=i+3) {
suma+=i;
}
for (m =0;m<b;m=m+5) {
suma+=m;
}
for (n =15;n<b;n+=15) {
suma-=n;
}

Serial.println (suma);

Serial.readString();
}

in python:

suma,tri,pet = 0,0,0
b=1000
for i in range (1,b):
if i % 3 == 0:
suma+=i

for m in range (1,b):
if m % 5 == 0:
suma+=m

for n in range (1,b):
if n % 15 == 0:
suma-=n

print (suma)

first problem is done 🙂 .

Problem 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

Thank you for watching.