# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
885959 | karimov | Odd-even (IZhO11_oddeven) | C++17 | 0 ms | 348 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>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fio(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout)
void YES(bool t=1){std::cout<<(t?"YES\n":"NO\n");}
void NO(bool t=1){YES(!t);}
const int MOD = 1000000007;
//#define int long long
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
/*
|------------------------------------|
|1 2 3 4 5 6 7 8 9 10 11|
|------------------------------------|
|1, 2, 4, 5, 7, 9, 10, 12, 14, 16, 17|
|------------------------------------|
1: 1
2: 2
3: 2
4: 3
5: 3
6: 3
7: 4
8: 4
9: 4
10: 4
11: 5 17
12: 5 19
13: 5 21
14: 5 23
15: 5 25
1
2 4
5 7 9
10 12 14 16
17 19 21 23 25
26 28 30 32 34 36
37 39 41 43 45 47 49
50 52 54 56 58 60 62 64
65
ODD: 4*n^2 + 1
EVEN: 4*n^2 + 4*n + 2
1 5 17 37
*/
void solve() {
double n;cin>>n;
int x = ceil((ceil(sqrt(n*8+1))-1)/2);
// cout << "x: "<<x << endl;
if(x%2==1){
int d = (x+1)/2-1;
// cout << "d: "<<d << endl;
// cout << "f: "<<(d*d*4+1)<<endl;
x--;
cout << (d*d*4+1)+(2*(n-(x*(x+1)/2)-1))<<endl;
} else {
int d = x/2-1;
// cout << "d: "<<d << endl;
// cout << "f: "<<(d*d*4+1)<<endl;
x--;
cout << (d*d*4+4*d+2)+(2*(n-(x*(x+1)/2)-1))<<endl;
}
// cout << x<<endl;
}
int main() {
FAST
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |