fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. inline int summ(long long x)
  8. {
  9. int res = 0;
  10. while (x)
  11. {
  12. res += x % 10ll;
  13. x /= 10ll;
  14. }
  15. return res;
  16. }
  17.  
  18. int main()
  19. {
  20. long long n;
  21. cin >> n;
  22. for (int s=1;s<=18*9;s++)
  23. {
  24. unsigned long long d = sqrt(1.0*s*s+4*n);
  25. if (d*d!=s*s+4*n)
  26. continue;
  27. long long x = (-s +(long long)d) / 2ll;
  28. if (summ(x) == s)
  29. {
  30. cout << x;
  31. return 0;
  32. }
  33. }
  34. cout << -1;
  35. return 0;
  36. }
Success #stdin #stdout 0s 3416KB
stdin
110
stdout
10