Submission

Status:

[PPPP-SSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: anonymous

Problemset: ขนมของเซ้น143 (v.ง่าย)

Language: cpp

Time: 0.005 second

Submitted On: 2026-10-25 20:38:43

#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    long long a = 1,b = n,s = (n*(n+1))/2;
    long long ans = 1e18;
    while(a <= b){
        long long mid = (a + b)/2;
        long long l = (mid*(mid+1))/2;
        long long r = s-l;

        ans = min(abs(l - r),ans);
        if(l < r){
            a = mid+1;
        }
        else{
            b = mid-1;
        }
    }

    cout << ans;
    return 0;

}