Submission #379805

# Submission time Handle Problem Language Result Execution time Memory
379805 2021-03-19T10:49:33 Z SolarSystem Odd-even (IZhO11_oddeven) C++17
0 / 100
1 ms 364 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <random>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long n;
    cin >> n;

    long long l = 0, r = 1e18;

    while (l + 1 < r) {
        long long m = (l + r) / 2;

        if (m > (2e18 + m - 1) / (m + 1) && m * (m + 1) / 2 > n) {
            r = m;
        } else {
            l = m;
        }
    }
  
    if (l * (l + 1) / 2 == n) cout << l * l;
    else {
        cout << l * l + (n - l * (l + 1) / 2) * 2 - 1;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -