Submission
Status:
[PPPPPPPPPP][PPPPP]
Score: 100
User: Nathlol2
Problemset: ขนมของเซ้น143 (v.ยาก)
Language: cpp
Time: 0.002 second
Submitted On: 2025-01-14 17:02:30
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll ans = LLONG_MAX;
ll sum(ll n){
return (n * (n + 1)) / 2;
}
int n;
void bs(int l, int h){
if(l >= h) return;
int m = (l + h) / 2;
ll sl = sum(m);
ll sr = sum(n) - sl;
ll diff = abs(sl - sr);
ans = min(ans, diff);
if(sl < sr){
bs(m + 1, h);
}else{
bs(l, m);
}
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
bs(1, n);
cout << ans;
}