# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1108439 | Tsagana | Odd-even (IZhO11_oddeven) | C++14 | 1 ms | 508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define lnl long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
lnl findsquare(lnl s) {
if (s == 0 || s == 1) return s;
lnl l = 1, r = s / 2, ans;
while (l <= r) {
lnl M = (l + r) / 2;
lnl sqr = M * M;
if (sqr == s) return M;
if (sqr <= s) {
l = M + 1;
ans = M;
}
else r = M - 1;
}
return ans;
}
void solve () {
lnl n; cin >> n;
lnl k = (findsquare((n * 8) + 1) - 1) / 2;
lnl s = (n - ((k * (k + 1)) / 2)) * 2;
if (!s) {cout << k * k; return ;}
k = (k * k) - 1;
cout << k + s;
}
int main() {IOS solve(); return 0;}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |