fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll=long long;
  4. using ull=unsigned long long;
  5. using vi=vector<int>;
  6. using vll=vector <ll>;
  7. using vvi=vector <vector <int>>;
  8. using vvll=vector <vector<ll>>;
  9. using pii=pair<int,int>;
  10. using pll=pair<ll,ll>;
  11. using str=string;
  12. using vpii=vector<pii>;
  13. #define fast ios_base::sync_with_stdio(false); cin.tie (nullptr); cout.tie (nullptr);
  14. #define nl '\n'
  15. #define F first
  16. #define S second
  17. #define het return 0;
  18. #define kt size()
  19.  
  20. #define FILE_NAME ""
  21.  
  22. int main () {
  23. fast
  24. // freopen(FILE_NAME ".INP", "r", stdin);
  25. // freopen(FILE_NAME ".OUT", "w", stdout);=
  26. ll n;
  27. cin >> n;
  28. ll l=1,r=1,sum=1,a=1,b=1,mx=1;
  29. while (r<=n) {
  30. if (sum<n) {
  31. r++;
  32. sum+=r;
  33. }
  34. else if (sum>n) {
  35. sum-=l;
  36. l++;
  37. }
  38. else {
  39. if (r-l+1>mx) {
  40. mx=r- l + 1;
  41. a=l;
  42. b=r;
  43. }
  44. r++;
  45. sum+=r;
  46. sum-=l;
  47. l++;
  48. }
  49. }
  50. cout << n << "=" << a << "+...+" << b;
  51. het
  52. }
Success #stdin #stdout 0.01s 5280KB
stdin
35
stdout
35=2+...+8