fork download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. typedef long double ld;
  4. # define pb push_back
  5. # define FAST_CODE ios_base::sync_with_stdio(false); cin.tie(NULL);
  6. using namespace std;
  7.  
  8. ll triF(ll n) {
  9. return (sqrt(2*n + ld(0.25)) - ld(0.5));
  10. }
  11.  
  12. ll calc(ll n) {
  13. if(n % 2 == 0) {
  14. return ((n/2)*(n+1));
  15. }
  16.  
  17. return ((n+1)/2)*n;
  18. }
  19.  
  20. ll calc1(ll n) {
  21. if(n % 2 == 0) {
  22. return (n/2)*(n-1);
  23. }
  24.  
  25. return ((n-1)/2)*n;
  26. }
  27.  
  28. ll nearest(ll n) {
  29. ll k = ld(ld(1) + ld(sqrt(8*n + ld(1))))/ld(2);
  30. return calc1(k);
  31. }
  32.  
  33. int main()
  34. {
  35. FAST_CODE;
  36. #ifndef ONLINE_JUDGE
  37. freopen("input.txt","r", stdin);
  38. freopen("output.txt","w", stdout);
  39. #endif
  40.  
  41. ll t;
  42. cin>>t;
  43. for(ll i=1; i<=t; ++i) {
  44. ll g;
  45. cin>>g;
  46. ll sumN = nearest(g);
  47. ll n = triF(g);
  48. ll ans = 0;
  49. for(ll i=n; i>=0; i--) {
  50. if((g - calc(i))%(i+1) == 0) {
  51. ans++;
  52. if((g - calc(i))/(i+1) == 0) {
  53. ans --;
  54. }
  55. }
  56. }
  57. cout<<"case #"<<i<<": "<<ans<<"\n";
  58.  
  59. }
  60. return 0;
  61. }
Success #stdin #stdout 0s 5604KB
stdin
2
10
125
stdout
case #1: 2
case #2: 4