Untitled

public
yousefkarem91 Sep 18, 2024 Never 55
Clone
C++ paste1.cpp 19 lines (19 loc) | 401 Bytes
1
#include <bits/stdc++.h>
2
using namespace std;
3
int main() {
4
int n;cin>>n;
5
long long prvR=1,prvSum=1; // Ri-1 sumi-1
6
int ans=1;
7
for(int i=2;i<=n;i++)
8
{
9
long long currR=prvR+i; //Ri
10
long long currSum=currR+prvSum; //sumi= sumi-1 + Ri
11
if(currSum<=n)
12
{
13
ans=i;
14
}
15
prvR=currR;
16
prvSum=currSum;
17
}
18
cout<<ans<<'\n';
19
}