Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int Pell(int x)
- {
- int i = 1, P0 = 2, P1 = 2, Pn = 2;
- do
- {
- int tmp = Pn;
- Pn = 2*Pn+P1;
- P0 = P1;
- P1 = tmp;
- i++;
- }
- while (i <= x);
- return P1;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- int n;
- cin >> n;
- cout << Pell(n) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement