fork(3) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <iomanip>
  13. #define dibs reserve
  14. #define OVER9000 1234567890
  15. #define patkan 9
  16. #define tisic 47
  17. #define soclose 10e-7
  18. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  19. #define chocolate win
  20. #define ff first
  21. #define ss second
  22. #define abs(x) ((x < 0)?-(x):(x))
  23. // mylittlepony
  24. using namespace std;
  25.  
  26. int main() {
  27. // freopen("army.in","r",stdin);
  28. int T;
  29. scanf(" %d",&T);
  30. for(int t =0; t < T; t++) {
  31. long long N;
  32. scanf(" %lld",&N);
  33.  
  34. long long a =0, b =2000000;
  35. while(b-a > 1) {
  36. long long c =(a+b)/2;
  37. long long s =c*(c+1)*(2*c+1)/6;
  38. if(s >= N) b =c;
  39. else a =c;}
  40.  
  41. long long ans =a*a;
  42. N -=a*(a+1)*(2*a+1)/6;
  43. if(N <= b*(b+1)/2) {
  44. a =-1;
  45. while(b-a > 1) {
  46. long long c =(b+a)/2;
  47. if(c*(c+1)/2 >= N) b =c;
  48. else a =c;}
  49. ans +=b;}
  50. else {
  51. ans +=2*b-1;
  52. N =b*b-N;
  53. a =0;
  54. while(b-a > 1) {
  55. long long c =(b+a)/2;
  56. if(c*(c+1)/2 > N) b =c;
  57. else a =c;}
  58. ans -=a;}
  59.  
  60. printf("Case %d: %lld\n",t+1,ans);}
  61. return 0;}
  62.  
  63. // look at my code
  64. // my code is amazing
Success #stdin #stdout 0s 3300KB
stdin
5
11
12
13
14
15
stdout
Case 1: 7
Case 2: 8
Case 3: 8
Case 4: 9
Case 5: 10