Created
August 20, 2015 15:13
-
-
Save luckypapa/92110c25ef69bafc7a2a to your computer and use it in GitHub Desktop.
fibonacci_get_zero_one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://www.acmicpc.net/problem/1003 | |
#include<stdio.h> | |
typedef struct CACHE{ | |
unsigned long long zero; | |
unsigned long long one; | |
} CACHE_T; | |
static CACHE_T cache[41] = {0}; | |
void initializeCache(void) { | |
cache[0].zero = 1; | |
cache[1].one = 1; | |
cache[2].zero = 1; | |
cache[2].one = 1; | |
for (int i = 3; i < 41; i++) { | |
cache[i].zero = cache[i-1].zero + cache[i-2].zero; | |
cache[i].one = cache[i-1].one + cache[i-2].one; | |
} | |
} | |
int main(void) { | |
initializeCache(); | |
int T; | |
scanf("%d", &T); | |
while(T-- > 0) { | |
int num; | |
scanf("%d", &num); | |
printf("%llu %llu\n", cache[num].zero, cache[num].one); | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment