Advertisement
fahimkamal63

Nth Fibonacci Number

May 1st, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #define mod 1000000007
  4. using namespace std;
  5.  
  6. int main(){
  7.     long long int num1 = 0, num2 = 1, num3, i, results[1000];
  8.     results[0] = num1, results[1] = num2;
  9.     for(i = 2; i < 1000; i++){
  10.         num3 = num1 + num2;
  11.         num3 %= mod;
  12.         num1 = num2; num2 = num3;
  13.         results[i] = num3;
  14.     }
  15.     int t; scanf("%d", &t);
  16.     while(t--){
  17.         int n; scanf("%d", &n);
  18.         printf("%lld\n", results[n]);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement