p246.out2
======================
4

=================
p246.ans2
======================
4

=================
p246.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int64_t n, two_n_minus_one;

void read() {
    cin >> two_n_minus_one;
    n = (two_n_minus_one + 1) / 2;
}

void solve() {
    // The necklace is beautiful iff there exist two black beads at distance
    // exactly n+1 (because then one of the open arcs has exactly n beads
    // strictly between them). The graph with edges i -- (i + (n+1)) mod (2n-1)
    // is a disjoint union of g = gcd(2n-1, n+1) cycles, each of length
    // (2n-1)/g. In a cycle of length len you can colour at most floor(len/2)
    // vertices black without creating a monochromatic edge. Hence the maximal
    // number of black beads without a beautiful configuration is g * floor(
    // ((2n-1)/g) / 2 ) and the minimal K that forces beauty for every possible
    // necklace is exactly one more.

    int64_t L = two_n_minus_one;
    int64_t dist = n + 1;
    int64_t g = gcd(L, dist);
    int64_t max_avoid = g * ((L / g) / 2);
    int64_t ans = max_avoid + 1;

    cout << ans << endl;
}

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

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}

=================
p246.in1
======================
6

=================
p246.out1
======================
3

=================
p246.ans1
======================
3

=================
statement.txt
======================
246. Black & White
time limit per test: 0.25 sec.
memory limit per test: 65536 KB
input: standard
output: standard



Consider a necklace made of 2N-1 black and white beads, K of which are black. Necklace is called "beautiful" if it is possible to choose two black beads (not necessarily different) in such a way that one of two necklace parts strictly between them contains exactly N beads.
For example, if N=4 and K=3, necklace "WBWBWBW" is beautiful, and necklace "BBWWBWW" is not.
You need to find minimal K for which every necklace of 2N-1 beads is beatiful.

Input
The first line of input contains odd integer number 2N-1 (5<=2N-1<=2^31-1).

Output
Output minimal K for which every necklace of 2N-1 beads is beatiful.

Sample test(s)

Input
Test #1
5

Test #2
7

Output
Test #1
3

Test #2
4
Author:	Alexey Preobrajensky
Resource:	Petrozavodsk Summer Training Sessions 2004
Date:	August 25, 2004









=================
p246.in2
======================
7

=================
