Create bruteforce.c

This commit is contained in:
Daniel Løvbrøtte Olsen 2015-12-31 15:24:44 +01:00
parent eef59d5ab3
commit ffaacf5fda

View 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);
}
}