Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* [A][M][C][B][N] / [K][R][I][P][6][8] */
- #include <bits/stdc++.h>
- #pragma warning(disable : 4996 4267 4068)
- using namespace std;
- template<typename type>
- using matrix = vector<vector<type>>;
- typedef long long ll;
- const char sp = ' ', nl = '\n';
- const int MOD = 1000000007;
- ll compute(ll n) {
- ll cnt(0);
- while (n) {
- cnt += n;
- if (n == 1) break;
- n = max(n / 3 - 1, 0ll) + 1;
- }
- return cnt;
- }
- ll find(ll n) {
- int st = 1, dr = 1.5e9, m;
- while (st <= dr) {
- m = (st + dr) / 2;
- if (compute(m) == n)
- return m;
- else {
- if (compute(m) < n)
- st = m + 1;
- else
- dr = m - 1;
- }
- }
- }
- int main() {
- ios::sync_with_stdio(NULL);
- cin.tie(nullptr), cout.tie(nullptr);
- (void)!freopen("croseta.in", "r", stdin);
- (void)!freopen("croseta.out", "w", stdout);
- ll n;
- cin >> n;
- cout << find(n / 2);
- }
Advertisement
Add Comment
Please, Sign In to add comment