# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define int long long
using namespace std;
const int N = 3e5 + 5;
int raod,cur,n,le,ri,ans,lef,rem;
main() {
cin>>n;
le = 0;
ri = 1e10;
while (le <= ri) {
int mid = (le + ri) / 2;
if ((mid*(mid + 1))/2 < n) {
ans = mid;
le = mid + 1;
} else ri = mid - 1;
}
lef = ans*ans+1;
rem = n - (ans*(ans + 1))/2;
cout<<lef + (rem - 1)*2<<endl;
}
Compilation message
oddeven.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
288 KB |
Output is correct |
13 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |