#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define foreach(it, S) for (__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define all(x) x.begin(), x.end()
#define endl '\n'
#define _ ios_base :: sync_with_stdio(false); cin.tie(NULL);
#ifdef inputf
#define fname ""
#else
#define fname "" // <- Here
#endif
const double eps = 1e-9;
const int MaxN = int(2e5) + 256;
const int MOD = int(1e9) + 7;
template <typename T> inline T gcd(T a, T b) {
return b ? gcd (b, a % b) : a;
}
inline bool Palindrome(const string& s) {
return equal(s.begin(), s.end(), s.rbegin());
}
int main() { // _
#ifdef lcl
freopen(fname".in", "r", stdin);
freopen(fname".out", "w", stdout);
#endif
ll x; cin >> x;
if (x == 1) {
cout << 1;
return 0;
}
ll l = 0, r = 1000000000;
while (r - l > 1) {
ll m = l + (r - l) / 2;
if (m * (m + 1) / 2 >= x)
r = m;
else
l = m;
}
ll ans = r;
if (r * (r + 1) / 2 >= x)
ans = l;
// cerr << ans << " " << l << " " << r << endl;
ll k = ans * ans + 1;
k += 2 * (x - ans * (ans + 1) / 2 - 1);
cout << k;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1716 KB |
Output is correct |
2 |
Correct |
0 ms |
1716 KB |
Output is correct |
3 |
Correct |
0 ms |
1716 KB |
Output is correct |
4 |
Correct |
0 ms |
1716 KB |
Output is correct |
5 |
Correct |
0 ms |
1716 KB |
Output is correct |
6 |
Correct |
0 ms |
1716 KB |
Output is correct |
7 |
Correct |
0 ms |
1716 KB |
Output is correct |
8 |
Correct |
0 ms |
1716 KB |
Output is correct |
9 |
Correct |
0 ms |
1716 KB |
Output is correct |
10 |
Correct |
0 ms |
1716 KB |
Output is correct |
11 |
Correct |
0 ms |
1716 KB |
Output is correct |
12 |
Correct |
0 ms |
1716 KB |
Output is correct |
13 |
Incorrect |
0 ms |
1716 KB |
Output isn't correct |
14 |
Incorrect |
0 ms |
1716 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
1716 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
1716 KB |
Output isn't correct |
17 |
Incorrect |
0 ms |
1716 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
1716 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
1716 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
1716 KB |
Output isn't correct |
21 |
Incorrect |
0 ms |
1716 KB |
Output isn't correct |
22 |
Incorrect |
0 ms |
1716 KB |
Output isn't correct |