[HDU] [2070] Fibbonacci Number

Problem Description

Loading...

Problem Analysis

The hint is quite friendly
This problem is just about finding the pattern
Not particularly hard

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
int main() {
	__int64 i,x,re,rea,reb;
	while(scanf("%lld",&x),x!=-1) {
		if(x==0)
			printf("0\n");
		else if(x==1)
			printf("1\n");
		else {
			for(i=1,rea=1,reb=0; i<x; i++) {
				re=rea+reb;
				reb=rea;
				rea=re;
			}
			printf("%lld\n",re);
		}
	}
	return 0;
}

Hmm… come to think of it, the problems I was doing back then didn’t seem all that hard
-.-

Loading...