fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long n, k, x, y;
  5.  
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. freopen("file.inp", "r", stdin);
  11. freopen("file.out", "w", stdout);
  12.  
  13. cin >> n >> k >> x >> y;
  14.  
  15. long long cnt_scp = sqrt(n);
  16.  
  17. long long ans_1 = x;
  18.  
  19. for (long long j = 1; j <= 3 * k; j++)
  20. {
  21. if(j % 3 == 1)
  22. {
  23. long long x_root = sqrt(ans_1);
  24.  
  25. if(x_root * x_root == ans_1)
  26. {
  27. ans_1 = x_root;
  28. }
  29. else
  30. {
  31. ans_1 = ans_1 + (cnt_scp - x_root);
  32. }
  33. }
  34. else if(j % 3 == 2)
  35. {
  36. long long x_root = sqrt(ans_1);
  37.  
  38. if(x_root * x_root == ans_1)
  39. {
  40. ans_1 = x_root + n - cnt_scp;
  41. }
  42. else
  43. {
  44. ans_1 -= x_root;
  45. }
  46. }
  47. else
  48. {
  49. ans_1 = n - ans_1 + 1;
  50. }
  51. }
  52.  
  53. long long ans_2 = y;
  54.  
  55. for (long long i = 3 * k; i >= 1; i--)
  56. {
  57. if(i % 3 == 0)
  58. {
  59. ans_2 = n - ans_2 + 1;
  60. }
  61. else if(i % 3 == 2)
  62. {
  63. if(ans_2 > n - cnt_scp)
  64. {
  65. long long x_root = ans_2 + cnt_scp - n;
  66. ans_2 = x_root * x_root;
  67. }
  68. else
  69. {
  70. long long r = round(sqrt(ans_2));
  71. ans_2 = ans_2 + r;
  72. }
  73. }
  74. else
  75. {
  76. if(ans_2 <= cnt_scp)
  77. {
  78. ans_2 = ans_2 * ans_2;
  79. }
  80. else
  81. {
  82. long long b = ans_2 - cnt_scp;
  83. long long r = round(sqrt(b));
  84. ans_2 = b + r;
  85. }
  86. }
  87. }
  88.  
  89. cout << ans_1 << " " << ans_2;
  90. }
  91.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty