• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Apr 20th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2.
3. int sqr(int n) {
4.   return n * n;
5. }
6.
7. int main() {
8.   int r{};
9.   std::cin >> r;
10.   int x{};
11.   int y{};
12.   for (x = 0; sqr(x - 1) <= r; ++x) {}
13.   while (y <= x) {
14.     if (abs(r - sqr(x - 1) - sqr(y)) < abs(r - sqr(x + 1) - sqr(y)) &&
15.         abs(r - sqr(x - 1) - sqr(y)) < abs(r - sqr(x)     - sqr(y + 1))) {
16.       x -= 1;
17.     } else if (abs(r - sqr(x + 1) - sqr(y)) < abs(r - sqr(x - 1) - sqr(y)) &&
18.                abs(r - sqr(x + 1) - sqr(y)) < abs(r - sqr(x)     - sqr(y + 1))) {
19.       x += 1;
20.     } else {
21.       y += 1;
22.     }
23.
24.     if ((sqr(x) + sqr(y)) == r && x * y != 0) {
25.       std::cout << x << " " << y << std::endl;
26.     }
27.   }
28.   return 0;
29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top