fork download
  1. /*
  2. ==================================+
  3. INPUT: |
  4. ------------------------------ |
  5.  
  6. ------------------------------ |
  7. ==================================+
  8. OUTPUT: |
  9. ------------------------------ |
  10.  
  11. ------------------------------ |
  12. ==================================+
  13. */
  14.  
  15. #include<bits/stdc++.h>
  16. using namespace std;
  17.  
  18. #define ll long long
  19. #define el "\n"
  20.  
  21. ll n, m, k, l, r, ans;
  22.  
  23. ll f(ll x)
  24. {
  25. ll c = 0;
  26. for (ll i = 1; i <= m; i++)
  27. {
  28. if (x - i * i < 0)
  29. {
  30. break;
  31. }
  32. ll j = sqrt(x - i * i);
  33. while ((j + 1) * (j + 1) <= x - i * i)
  34. {
  35. j++;
  36. }
  37. while (j * j > x - i * i)
  38. {
  39. j--;
  40. }
  41. c += min(n, j);
  42. }
  43. return c;
  44. }
  45.  
  46. int main()
  47. {
  48. ios_base::sync_with_stdio(0);
  49. cin.tie(0);cout.tie(0);
  50.  
  51. // freopen("BAI1.INP" , "r" , stdin);
  52. // freopen("BAI1.OUT" , "w" , stdout);
  53.  
  54. cin >> n >> m >> k;
  55. if (m > n)
  56. {
  57. swap(m, n);
  58. }
  59. l = 2;
  60. r = m * m + n * n;
  61. while (l <= r)
  62. {
  63. ll mid = (l + r) / 2;
  64. if (f(mid) >= k)
  65. {
  66. ans = mid;
  67. r = mid - 1;
  68. }
  69. else
  70. {
  71. l = mid + 1;
  72. }
  73. }
  74. cout << ans;
  75. }
  76. /// Minh Khôi, Amsterdam school, the 10 math 1 class
  77. /// user: Minhkhoitht
  78.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty