#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
ll n;
cin>>n;
n--;
ll l = 0,r = 1e9,le = 0;
while(l<=r) {
ll m = (l+r)/2;
if (m*(m+1)/2 + m > n) {
r= m-1;
}
else {
l = m+1;
le = m;
}
}
ll ans = 1;
ans += le*(le+1) + le;
n -= le*(le+1)/2 + le;
if (n >= 1) {
ans++;
n--;
ans+= n*2;
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |