fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. vector <int> gd;
  8. gd.push_back(1);
  9. int n; cin >> n;
  10. long long int i = 1, elem;
  11. for(; elem < n; i++) {
  12. elem = gd[i-1]+2*i;
  13. gd.push_back(elem);
  14. }
  15. int nearest = (abs(n - gd[i-1]) > (n - gd[i-2]) ? gd[i-2] : gd[i-1]);
  16. int nearest_i = (abs(n - gd[i-1]) > (n - gd[i-2]) ? i-2 : i-1) +1;
  17. // for (auto elem : gd) {
  18. // cout << elem << ' ';
  19. // }cout << endl;
  20. if((nearest_i-1) % 2 == 0) {
  21. if((n - nearest) < 0) {
  22. cout << nearest_i << ' ' << nearest_i - abs(n - nearest);
  23. } else {
  24. cout << nearest_i - abs(n - nearest) << ' ' << nearest_i;
  25. }
  26. } else {
  27. if((n - nearest) < 0) {
  28. cout << nearest_i - abs(n - nearest) << ' ' << nearest_i;
  29. } else {
  30. cout << nearest_i << ' ' << nearest_i - abs(n - nearest);
  31. }
  32. }
  33. }
Success #stdin #stdout 0s 4880KB
stdin
15
stdout
4 2