Submission

Status:

[P-SSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: anonymous

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

Language: cpp

Time: 0.003 second

Submitted On: 2026-10-25 20:32:06

#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;
    long long s = (n*(n+1)) / 2,ans = 1e18;

    while ( a <= b){
        long long mid = (a + b) / 2;

        ans = min(abs((mid*(mid+1)) - s) , ans);
        if(mid*(mid+1) / 2 < s - a) a = mid + 1;
        else b = mid - 1;
    }

    cout << ans;
    return 0;

}