Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int r[1000001] = {1, 1, 2, 3};
  6. int przestaw(int n){
  7. if (r[n] == 0)
  8. r[n] = (przestaw(n - 1) + przestaw(n - 2)) % 1000000;
  9. return r[n];
  10. }
  11. int main()
  12. {
  13. int n;
  14. cin >> n;
  15. if (n <= 1000) cout <<przestaw(n) << endl;
  16. else {
  17. for (int i = 4; i <= n; i++)
  18. r[i] = (r[i - 1] + r[i - 2]) % 1000000;
  19. cout << r[n] <<endl;
  20. }
  21. return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement