#include<stdio.h> int main(){ int M; scanf("%d",&M); while (M!=0) { if (M == 1) { printf("1\n"); } else if (M == 2) { printf("2\n"); } else { long long int small; long long int big; long long int sum=0; long long int temp; small=1; big=1; for (int i = 3; i <=M ; i++) { temp=small; small=big; big=big+temp; sum=big+small; } printf("%lld\n",sum); } scanf("%d",&M); } return 0; } |
Double click to view unformatted code.