Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int Pell(int x)
  5. {
  6.     int i = 1, P0 = 2, P1 = 2, Pn = 2;
  7.     do
  8.     {
  9.         int tmp = Pn;
  10.         Pn = 2*Pn+P1;
  11.         P0 = P1;
  12.         P1 = tmp;
  13.         i++;
  14.     }
  15.     while (i <= x);
  16.  
  17.     return P1;
  18. }
  19.  
  20. int main()
  21. {
  22.     ios_base::sync_with_stdio(0);
  23.     int n;
  24.  
  25.     cin >> n;
  26.  
  27.     cout << Pell(n) << endl;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement