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