# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170699 | Lightning | Odd-even (IZhO11_oddeven) | C++14 | 2 ms | 504 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 <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
#define int ll
const int N = 2e5 + 5;
const int INF = 1e9 + 5;
int n;
int sum(int x) {
return (x * (x + 1)) / 2;
}
main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
int l = 1, r = n;
while(l < r) {
int mid = (l + r) / 2;
if(sum(mid) >= n) r = mid;
else l = mid + 1;
}
int num = r;
int fir = (num * (num - 2)) + 2;
int pos = n - sum(num - 1);
cout << fir + (2 * (pos - 1));
return 0;
}
/*
If you only do what you can do,
You will never be more than you are now!
We must all suffer from one of two pains: the pain of discipline or the pain of regret.
The difference is discipline weighs grams while regret weighs tons.
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |