SHARE
TWEET

Untitled

a guest Jan 24th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     freopen("division.in", "r", stdin);
  8.     freopen("division.out", "w", stdout);
  9.     ios::sync_with_stdio(0);
  10.     int n;
  11.     cin >> n;
  12.     int o = n / 3;
  13.     int d = 4;
  14.     int mi = max(o - d, 1);
  15.     int ma = min(o + d, n);
  16.     long long ans = (long long) n * n;
  17.     long long q1, q2, q3 = 0, a, b, c;
  18.     for ( a = mi; a <= ma; a++ )
  19.         for ( b = a + 1; b <= ma; b++ )
  20.             for ( c = b + 1; c <= ma; c++ )
  21.                 if (a + b + c == n && a * a + b * b + c * c < ans)
  22.                 {
  23.                     ans = a * a + b * b + c * c;
  24.                     q1 = a;
  25.                     q2 = b;
  26.                     q3 = c;
  27.                 }
  28.     cout << q1 << " " << q2 << " " << q3;
  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. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top