Untitled

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