Create bruteforce.c
This commit is contained in:
parent
eef59d5ab3
commit
ffaacf5fda
41
Project-Euler/002/bruteforce.c
Normal file
41
Project-Euler/002/bruteforce.c
Normal file
@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Use:
|
||||
// bruteforce
|
||||
// n numbers to calculate (PE 1)
|
||||
// number #1 to calculate (PE 4000000)
|
||||
// number #2 to calculate
|
||||
// ...
|
||||
// number n to calculate
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
long arr[n];
|
||||
for(int i = 0; i < n; i++){
|
||||
scanf("%li",&arr[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
long sum = 2;
|
||||
int a = 1, b = 2;
|
||||
while (1)
|
||||
{
|
||||
int c = a + b;
|
||||
a = b;
|
||||
b = c;
|
||||
if (b > arr[i])
|
||||
break;
|
||||
if (b % 2 == 0)
|
||||
{
|
||||
sum += b;
|
||||
}
|
||||
}
|
||||
printf("%li\n", sum);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user