fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long n,k,x,y;
  4. int main()
  5. {
  6. freopen("file.inp", "r", stdin);
  7. freopen("file.ans", "w", stdout);
  8. cin >> n >> k >> x >> y;
  9. long long cnt_scp=sqrt(n),ans_1,ans_2;
  10. for (long long i=1; i<=n; i++)
  11. {
  12. long long pos= i;
  13. for (long long j=1; j<=3*k; j++)
  14. {
  15. if(j%3==1)
  16. {
  17. long long x = sqrt(pos);
  18. if(x*x==pos)
  19. {
  20. pos=x;
  21. }
  22. else
  23. {
  24. pos=pos+(cnt_scp-x);
  25. }
  26. }
  27. else if(j%3==2)
  28. {
  29. long long x = sqrt(pos);
  30. if(x*x==pos)
  31. {
  32. pos=x+n-cnt_scp;
  33. }
  34. else
  35. {
  36. pos-=x;
  37. }
  38. }
  39. else
  40. {
  41. if(pos<=n/2)
  42. {
  43. pos=n-pos+1;
  44. }
  45. else
  46. {
  47. pos= 1 + (n-pos);
  48. }
  49. }
  50. }
  51. if(pos==y)
  52. {
  53. ans_2=i;
  54. }
  55. if(i==x)
  56. {
  57. ans_1=pos;
  58. }
  59. }
  60. cout << ans_1 << " " << ans_2;
  61. }
  62.  
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty