fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int,int> ii;
  7. typedef unsigned long long ull;
  8.  
  9. #define X first
  10. #define Y second
  11. #define pb push_back
  12. #define mp make_pair
  13. #define ep emplace_back
  14. #define EL printf("\n")
  15. #define sz(A) (int) A.size()
  16. #define FOR(i,l,r) for (int i=l;i<=r;i++)
  17. #define FOD(i,r,l) for (int i=r;i>=l;i--)
  18. #define fillchar(a,x) memset(a, x, sizeof (a))
  19. #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  20.  
  21. int T;
  22. ll n, x, k, h;
  23.  
  24. void solve(ll t) {
  25. if (t < 0) return ;
  26. ll p = t*(t+1)/2;
  27. p *= p;
  28. if (t > h and abs(n-p) <= abs(k)) {
  29. k = n-p;
  30. h = t;
  31. }
  32. }
  33.  
  34. int main() {
  35. // freopen("INP.TXT", "r", stdin);
  36. // freopen("OUT.TXT", "w", stdout);
  37.  
  38. scanf("%d", &T);
  39. while (T--) {
  40. cin >> n;
  41. if (n == 0) {
  42. printf("0 1 1\n");
  43. continue;
  44. }
  45. k = n;
  46. h = 0;
  47. x = sqrt(2*sqrt(n));
  48. for (ll t=x-3; t<=x+3; t++) solve(t);
  49. if (k == 0) printf("1 %lld\n", h);
  50. else printf("0 %lld %lld\n", -k, h);
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 5580KB
stdin
100
446380
866234
882804
209647
402620
126976
779563
432000
711056
712905
631559
276157
260705
690696
110370
190663
628325
376892
425308
163532
747364
875057
427934
136205
829916
402409
278576
860145
587614
136969
649968
652980
275323
649913
456585
714434
492572
294758
864369
182783
958447
591248
739972
875435
409229
817020
822088
550405
262212
100661
195368
621061
963101
996502
590866
911222
403353
550792
257719
549345
874857
894121
462643
217612
332327
168842
270479
307082
252726
555590
409985
473368
723056
121121
898233
455458
670444
537152
609130
161301
191610
577712
321404
236742
280568
488094
909045
414872
477648
256012
873487
891592
744376
210552
252331
631069
772174
550222
177973
859878
stdout
0 -2824 36
0 28682 43
0 12112 43
0 6578 30
0 -5720 35
0 -3775 26
0 35846 42
0 11556 36
0 30265 41
0 28416 41
0 -23159 39
0 2627 32
0 -14689 31
0 -18296 40
0 -4745 25
0 -1438 29
0 -19925 39
0 20008 35
0 18248 36
0 1304 28
0 -6043 41
0 19859 43
0 15622 36
0 6679 27
0 -14507 42
0 -5509 35
0 208 32
0 34771 43
0 20786 39
0 5915 27
0 22432 40
0 19420 40
0 3461 32
0 22487 40
0 -13029 36
0 26887 41
0 1637 37
0 -15974 32
0 30547 43
0 6442 29
0 21653 44
0 17152 39
0 1349 41
0 19481 43
0 -12329 35
0 -1611 42
0 -6679 42
0 -1324 38
0 -16196 31
0 4964 25
0 -6143 29
0 -12661 39
0 16999 44
0 -16402 44
0 17534 39
0 -16306 43
0 -6453 35
0 -1711 38
0 -11703 31
0 -264 38
0 20059 43
0 795 43
0 -19087 36
0 -1387 30
0 -17606 33
0 -4006 28
0 8305 32
0 7639 33
0 -6710 31
0 -6509 38
0 -13085 35
0 20841 37
0 18265 41
0 2080 26
0 -3317 43
0 -11902 36
0 1956 40
0 11929 38
0 -730 39
0 3535 28
0 -2385 29
0 -28631 38
0 -6683 33
0 9274 31
0 -1784 32
0 6115 37
0 -14129 43
0 -17972 35
0 16561 37
0 -9996 31
0 21429 43
0 3324 43
0 -3055 41
0 5673 30
0 -6315 31
0 -22669 39
0 -30853 41
0 -1141 38
0 11252 29
0 35038 43