Submission
Status:
[PPPPPPPPP]
Score: 100
User: Dormon
Problemset: ขนมของเซ้น143 (v.ง่าย)
Language: cpp
Time: 0.003 second
Submitted On: 2024-12-03 09:54:22
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#define debug(...) Debug(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
const bool TEST_CASE = 0;
template<typename T>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* name, T value) {
std::cout << name << " : " << value << '\n';
}
template<typename T, typename... Args>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* names, T value, Args... args) {
const char* comma = strchr(names, ',');
std::cout.write(names, comma - names) << " : " << value << " | ";
Debug(comma + 1, args...);
}
void solve(){
int64_t n;
cin >> n;
auto sum = [&](int64_t a) -> int64_t {
return a*(a+1)/2;
};
int64_t all = sum(n);
int64_t l = 0, r = n, ans = 1e9+0ll;
while (l <= r){
int64_t mid = l+r>>1ll;
int64_t a = sum(mid), b = all - a;
ans = min(ans, abs(a - b));
if (a > b)
r = mid-1;
else
l = mid+1;
//debug(a, b, mid, ans);
}
cout << ans << '\n';
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int q = 1;
if (TEST_CASE) cin >> q;
while (q--){
solve();
}
}