#include<bits/stdc++.h> #define int long long usingnamespace std; using ll = longlong; using arr2 = array<int, 2>; using arr3 = array<int, 3>; constint N = (int)2e5 + 9; constint M = (int)1e5 + 9; constint mod = (int)1e9 + 7;
voidsolve(){ int n; cin >> n; if (n == 2) { cout << "2\n"; return ; } if (n == 3) { cout << "3\n"; return ; } cout << n % 2 << "\n"; }
#include<bits/stdc++.h> #define int long long usingnamespace std; using ll = longlong; using arr2 = array<int, 2>; using arr3 = array<int, 3>; constint N = (int)2e5 + 9; constint M = (int)1e5 + 9; constint mod = (int)1e9 + 7;
voidsolve(){ int s, k, m; cin >> s >> k >> m; int num = m / k; int x = m % k; if (num % 2 == 0) { cout << max(0ll, s - x) << "\n"; return ; } cout << max(0ll, min(k, s) - x) << "\n"; }
#include<bits/stdc++.h> #define int long long usingnamespace std; using ll = longlong; using arr2 = array<int, 2>; using arr3 = array<int, 3>; constint N = (int)2e5 + 9; constint M = (int)1e5 + 9; constint mod = (int)1e9 + 7;
voidsolve(){ int n, k; cin >> n >> k; int ans = 0; bool f = 0; if (n == k) { cout << "0\n"; return ; } while (n) { ans++; if (n & 1) f = 1; n >>= 1; if (f && (n == k || n + 1 == k)) { cout << ans << "\n"; return ; } if (!f && n == k) { cout << ans << "\n"; return ; } } cout << "-1\n";
#include<bits/stdc++.h> #define int long long usingnamespace std; using ll = longlong; using arr2 = array<int, 2>; using arr3 = array<int, 3>; constint N = (int)2e5 + 9; constint M = (int)1e5 + 9; constint mod = (int)1e9 + 7;
voidsolve(){ int n, k; cin >> n >> k; int tmp = 0; while (n) { tmp++; n >>= 1; } n = tmp; int ans = 0; for (int i = 0; i < n - 1; i++) { if (i + i + 1 <= k) continue; if (i + 1 > k) ans += (1 << i); else { int num = max(k - i, 0ll); int cnt = 1; auto sum = [](int num, int i) -> int { int cnt = 1; int k = 1; for (int j = i - num + 1; j <= i; j++) { cnt *= j; cnt /= k; k++; } return cnt; }; for (int j = num; j <= i; j++) { ans += sum(j, i); } } } if (2 + n - 2 > k) ans++; cout << ans << "\n";