Guest User

Untitled

a guest
May 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. long long i, j, n, x, y, fx, fy, tmp;
  7. long long a[2] = {1,0};
  8. int b[2] = {0,1};
  9.  
  10. long long find(long long v){
  11. if (v == x)
  12. return fx;
  13. if (v == x + 1)
  14. return fy;
  15. if (v > x + 1){
  16. for (i = x + 2; i <= v; i++){
  17. tmp = fy;
  18. fy += fx;
  19. fx = tmp;
  20. }
  21. return fy;
  22. }
  23. for (i = x - 1; i >= v; i--){
  24. tmp = fx;
  25. fx = fy - fx;
  26. fy = tmp;
  27. }
  28. return fx;
  29. }
  30.  
  31. int main(){
  32. cin >> x >> fx >> y >> fy >> n;
  33. if (x > y){
  34. swap(x,y);
  35. swap(fx,fy);
  36. }
  37.  
  38. a[0] = b[1] = 1;
  39.  
  40. for (i = x + 2; i <= y; i++)
  41. for (j = 0; j < 2; j++){
  42. tmp = b[j];
  43. b[j] += a[j];
  44. a[j] = tmp;
  45. }
  46.  
  47. fy = (fy - b[0] * fx) / b[1];
  48. cout << find(n) << endl;
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment