Skip to content

Commit

Permalink
2149 C
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPLopes committed Dec 31, 2019
1 parent e11e65f commit 5bd4f41
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions C/2149.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>

#define N 18

// baseado na solução https://github.com/malbolgee/URI/blob/master/2149.c com adaptações

typedef long long ll;

ll *makePhilSequence()
{
ll *fib = (ll *)malloc(sizeof(ll) * N);
int i;
fib[1] = 0;
fib[2] = 1;
for (i = 3; i <= N; ++i)
if (i % 2 == 0)
fib[i] = fib[i - 1] * fib[i - 2];
else
fib[i] = fib[i - 1] + fib[i - 2];
return fib;
}

int main(int argc, char const *argv[])
{
int in = 0;

ll *PhilSequence = makePhilSequence();

while (scanf("%d", &in) != EOF)
{
printf("%lld\n", PhilSequence[in]);
}

free(PhilSequence);

return 0;
}

0 comments on commit 5bd4f41

Please sign in to comment.