problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main(void) { long long n, k; cin >> n >> k; long long kk; kk = k; long long nn = 1000000000000000000; if (n % k == 0) { cout << 0 << endl; return (0); } while (1) { n = labs(n - k); if (n > nn) break; nn = n; } cout << min(kk, nn) << endl; }
#include <bits/stdc++.h> using namespace std; int main(void) { long long n, k; cin >> n >> k; long long kk; kk = k; long long nn = 1000000000000000000; if (n % k == 0) { cout << 0 << endl; return (0); } n = n % k; while (1) { n = labs(n - k); if (n > nn) break; nn = n; } cout << min(kk, nn) << endl; }
insert
12
12
12
13
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; using namespace std; int main() { ll n, k; cin >> n >> k; if (n % k == 0) { cout << 0 << endl; return 0; } for (ll i = 0; i < 1e17; ++i) { if ((abs(n - k)) < n) { n = abs(n - k); } else { break; } } cout << abs(n) << endl; return 0; }
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; using namespace std; int main() { ll n, k; cin >> n >> k; ll flag = n / k; n -= flag * k; if (n % k == 0) { cout << 0 << endl; return 0; } for (ll i = 0; i < 1e17; ++i) { if ((abs(n - k)) < n) { n = abs(n - k); } else { break; } } cout << abs(n) << endl; return 0; }
insert
7
7
7
9
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k; int main() { cin >> n >> k; if (k >= n) { cout << min(n, k - n) << '\n'; } else { cout << min(n % k, k - (n % k)) << '\n'; } }
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n >> k; if (k >= n) { cout << min(n, k - n) << '\n'; } else { cout << min(n % k, k - (n % k)) << '\n'; } }
replace
4
5
4
5
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() int main() { LL n, k; cin >> n >> k; LL d = abs(n - k); LL x = n / d; LL ans = min(n - x * d, abs(n - x * (d + 1))); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() int main() { LL n, k; cin >> n >> k; cout << min(n % k, abs(n % k - k)) << endl; }
replace
10
15
10
11
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k, t; cin >> n >> k; t = n % k; cout << min(t, k - t); }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, t; cin >> n >> k; t = n % k; cout << min(t, k - t); }
replace
4
5
4
5
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> #define foi(i, k, n) for (int i = (int)k; i < (int)n; ++i) using namespace std; using ii = pair<int, int>; using ll = long long; constexpr int MAXN = 5 + 1000; int a[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ll a, b; cin >> a >> b; cout << a % abs(a - b) << '\n'; return 0; }
#include <bits/stdc++.h> #define foi(i, k, n) for (int i = (int)k; i < (int)n; ++i) using namespace std; using ii = pair<int, int>; using ll = long long; constexpr int MAXN = 5 + 1000; int a[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ll n, k; cin >> n >> k; ll ans = n; for (int i = 0; i < 100; ++i) { if (n >= k) { n %= k; } else { n = abs(n - k); } ans = min(ans, n); } cout << ans << '\n'; return 0; }
replace
14
17
14
26
0
p02719
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int n, k; int main() { cin >> n >> k; cout << min(n % k, k - (n % k)); return 0; }
#include <algorithm> #include <iostream> using namespace std; long long n, k; int main() { cin >> n >> k; cout << min(n % k, k - (n % k)); return 0; }
replace
5
6
5
6
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n >> k; while (n > k) n -= k; n = min(n, k - n); cout << n; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n >> k; if (n > k) n %= k; n = min(n, k - n); cout << n; return 0; }
replace
6
8
6
8
TLE
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string.h> using namespace std; long long n, k, ans; map<int, int> mp; int main() { scanf("%lld%lld", &n, &k); if (n % k == 0) ans = 0; else { while (n > k) { n -= k; } if (k - n < n) ans = k - n; else ans = n; } printf("%lld\n", ans); }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string.h> using namespace std; long long n, k, ans; map<int, int> mp; int main() { scanf("%lld%lld", &n, &k); if (n % k == 0) ans = 0; else { if (n > k) { n %= k; } if (k - n < n) ans = k - n; else ans = n; } printf("%lld\n", ans); }
replace
16
18
16
18
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long n, k, mn; cin >> n >> k; mn = n; if (n % k > 0) { while (n > 0) { n = n - k; mn = min(abs(n), mn); } } else { mn = 0; } cout << mn << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long n, k, mn; cin >> n >> k; mn = n; if (n % k > 0) { mn = min(n - (n / k * k), abs(n - (n / k * k + k))); } else { mn = 0; } cout << mn << endl; }
replace
7
11
7
8
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; cout << min(n % m, m - (n % m)) << '\n'; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; cout << min(n % m, m - (n % m)) << '\n'; }
replace
3
4
3
4
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << min(n % k, abs(n % k - k)) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; cout << min(n % k, abs(n % k - k)) << endl; return 0; }
replace
3
4
3
4
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << min(n % k, abs(k - n % k)); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; cout << min(n % k, abs(k - n % k)); return 0; }
replace
3
4
3
4
0
p02719
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <stdio.h> #include <string> #include <vector> using ll = long long; using namespace std; typedef std::pair<int, int> ipair; bool lessPair(const ipair &l, const ipair &r) { return l.second < r.second; } bool greaterPair(const ipair &l, const ipair &r) { return l.second > r.second; } #define rep(i, n) for (int i = 0; i < (n); ++i) #define irep(i, n) for (int i = 0; i <= (n); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; --i) #define rirep(i, n) for (int i = n; i >= 0; --i) int factorical(int n) { int sum = 1; for (int i = 1; i <= n; ++i) { sum *= i; } return sum; } vector<int> divisors(int n) { vector<int> res; for (int i = 1; i * i <= n; ++i) { if (n % i != 0) continue; res.push_back(i); if (n / i == i) continue; // 上の行で追加済み。 res.push_back(n / i); } return res; } vector<ll> divisors_ll(ll n) { vector<ll> res; for (ll i = 1; i * i <= n; ++i) { if (n % i != 0) continue; res.push_back(i); if (n / i == i) continue; // 上の行で追加済み。 res.push_back(n / i); } return res; } void printVector(const vector<int> &vec) { for (int value : vec) { cout << value << " "; } cout << endl; } bool pal(string s) { int n = s.length() / 2; rep(i, n) { if (s[i] != s[s.length() - 1 - i]) return false; } return true; } int euclidean_gcd(int a, int b) { if (a < b) return euclidean_gcd(b, a); int r; while ((r = a % b)) { a = b; b = r; } return b; } vector<string> vec_sort_and_del(vector<string> s) { std::sort(s.begin(), s.end()); s.erase(std::unique(s.begin(), s.end()), s.end()); return s; } int main() { int n, k, nk, ans; cin >> n >> k; nk = n % k; ans = k - nk; if (ans < 0) ans = 0; cout << min(ans, nk) << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <stdio.h> #include <string> #include <vector> using ll = long long; using namespace std; typedef std::pair<int, int> ipair; bool lessPair(const ipair &l, const ipair &r) { return l.second < r.second; } bool greaterPair(const ipair &l, const ipair &r) { return l.second > r.second; } #define rep(i, n) for (int i = 0; i < (n); ++i) #define irep(i, n) for (int i = 0; i <= (n); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; --i) #define rirep(i, n) for (int i = n; i >= 0; --i) int factorical(int n) { int sum = 1; for (int i = 1; i <= n; ++i) { sum *= i; } return sum; } vector<int> divisors(int n) { vector<int> res; for (int i = 1; i * i <= n; ++i) { if (n % i != 0) continue; res.push_back(i); if (n / i == i) continue; // 上の行で追加済み。 res.push_back(n / i); } return res; } vector<ll> divisors_ll(ll n) { vector<ll> res; for (ll i = 1; i * i <= n; ++i) { if (n % i != 0) continue; res.push_back(i); if (n / i == i) continue; // 上の行で追加済み。 res.push_back(n / i); } return res; } void printVector(const vector<int> &vec) { for (int value : vec) { cout << value << " "; } cout << endl; } bool pal(string s) { int n = s.length() / 2; rep(i, n) { if (s[i] != s[s.length() - 1 - i]) return false; } return true; } int euclidean_gcd(int a, int b) { if (a < b) return euclidean_gcd(b, a); int r; while ((r = a % b)) { a = b; b = r; } return b; } vector<string> vec_sort_and_del(vector<string> s) { std::sort(s.begin(), s.end()); s.erase(std::unique(s.begin(), s.end()), s.end()); return s; } int main() { ll n, k, nk, ans; cin >> n >> k; nk = n % k; ans = k - nk; if (ans < 0) ans = 0; cout << min(ans, nk) << endl; return 0; }
replace
86
87
86
87
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K, sur, ans; cin >> N >> K; sur = N % K; ans = min(sur, K - sur); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int N, K, sur, ans; cin >> N >> K; sur = N % K; ans = min(sur, K - sur); cout << ans << endl; }
replace
4
5
4
5
0
p02719
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; #define PI 3.14159265358979 typedef long long int ll; const int inf = 1001001001; ll absc(ll a, ll b) { return (a - b > 0 ? a - b : b - a); } ll mini(ll a, ll b) { return (a > b ? b : a); } int main() { ll m, b, c, n, sum = 0, ans; string s, t; cin >> n >> m; ans = n; ans = mini(ans % n, ans); ans = mini(ans, absc(m, n % m)); ans = mini(absc(m, absc((n % m + n), m)), ans); cout << ans; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; #define PI 3.14159265358979 typedef long long int ll; const int inf = 1001001001; ll absc(ll a, ll b) { return (a - b > 0 ? a - b : b - a); } ll mini(ll a, ll b) { return (a > b ? b : a); } int main() { ll m, b, c, n, sum = 0, ans; string s, t; cin >> n >> m; ans = n; ans = mini(n % m, ans); ans = mini(ans, absc(m, n % m)); ans = mini(absc(m, absc((n % m + n), m)), ans); cout << ans; }
replace
23
24
23
24
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main() { int n, k, a, b; cin >> n >> k; a = n % k; if (a - k >= 0) { b = a - k; } else { b = k - a; } if (a >= b) { cout << b << endl; } else { cout << a << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main() { long long n, k, a, b; cin >> n >> k; a = n % k; if (a - k >= 0) { b = a - k; } else { b = k - a; } if (a >= b) { cout << b << endl; } else { cout << a << endl; } }
replace
5
6
5
6
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> #include <string> #include <vector> #define ll long long #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) using namespace std; int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } int main() { ll n, k; cin >> n >> k; while (n > abs(n - k)) { n = abs(n - k); } cout << n << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> #include <string> #include <vector> #define ll long long #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) using namespace std; int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } int main() { ll n, k; cin >> n >> k; if (n > k) n = n - (n / k) * k; while (n > abs(n - k)) { n = abs(n - k); } cout << n << endl; return 0; }
insert
15
15
15
17
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long int lld; int main() { lld N, K; cin >> N >> K; while (N > K) N = N - K; cout << min(N, K - N) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int lld; int main() { lld N, K; cin >> N >> K; if (N > K) N %= K; cout << min(N, K - N) << endl; }
replace
7
9
7
9
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long unsigned x, y, anti_rem; cin >> x >> y; if (x % y == 0) { cout << 0 << endl; } else if (x < y) { anti_rem = labs(x - y); cout << min(x, anti_rem) << endl; } else { while (x > y) { x = x - y; } long long unsigned xx = labs(x - y); cout << min(x, xx) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long unsigned x, y, anti_rem; cin >> x >> y; if (x % y == 0) { cout << 0 << endl; } else if (x < y) { anti_rem = labs(x - y); cout << min(x, anti_rem) << endl; } else { x = x % y; long long unsigned xx = labs(x - y); cout << min(x, xx) << endl; } return 0; }
replace
11
14
11
12
TLE
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> #define R(i, n) for (int i = 0; i < n; i++) #define S(a) scanf("%d", &a) #define S2(a, b) scanf("%d%d", &a, &b) #define S3(a, b, c) scanf("%d%d%d", &a, &b, &c) #define SL(a) scanf("%lld", &a) #define P(a) printf("%d", a) #define PL(a) printf("%lld", a); #define PY printf("%s", "Yes"); #define PN printf("%s", "No"); #define INF 1000000000 using namespace std; typedef long long ll; typedef pair<int, int> IR; int main() { ll n, k; SL(n); SL(k); ll now = n; while (true) { ll tmp = abs(k - n); if (tmp >= now) break; else { n = tmp; now = tmp; } } PL(n); }
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> #define R(i, n) for (int i = 0; i < n; i++) #define S(a) scanf("%d", &a) #define S2(a, b) scanf("%d%d", &a, &b) #define S3(a, b, c) scanf("%d%d%d", &a, &b, &c) #define SL(a) scanf("%lld", &a) #define P(a) printf("%d", a) #define PL(a) printf("%lld", a); #define PY printf("%s", "Yes"); #define PN printf("%s", "No"); #define INF 1000000000 using namespace std; typedef long long ll; typedef pair<int, int> IR; int main() { ll n, k; SL(n); SL(k); ll mod = n % k; ll diff = k - mod; PL(min(mod, diff)); }
replace
25
36
25
28
TLE
p02719
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; const int MAX = 700000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } /*第二引数で第一引数を割ったときの切り上げの計算*/ long long int maxtime(long long int x, long long int y) { return (x + y - 1) / y; } /*最大公約数*/ long long int lcm(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; if (number2 > number1) { m = number2; n = number1; } long long int s = -1; while (s != 0) { s = m % n; m = n; n = s; } return m; } /*最大公倍数*/ long long int gcd(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; return m / lcm(m, n) * n; } /*逆元計算*/ long long int modinv(long long a, long long m) { long long int b = m, u = 1, v = 0; while (b) { long long int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // index が条件を満たすかどうか vector<long long int> meguru; bool isOK(int index, int key) { if (meguru[index] >= key) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_search(int key) { int left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)meguru.size(); // 「index = // a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { long long int n, k; cin >> n >> k; long long int f = lcm(n, k); if (n <= k) { cout << min(k - n, n); return 0; } else { long long int c = n; n = n % k; cout << min(n, k - n); } }
#include "bits/stdc++.h" using namespace std; const int MAX = 700000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } /*第二引数で第一引数を割ったときの切り上げの計算*/ long long int maxtime(long long int x, long long int y) { return (x + y - 1) / y; } /*最大公約数*/ long long int lcm(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; if (number2 > number1) { m = number2; n = number1; } long long int s = -1; while (s != 0) { s = m % n; m = n; n = s; } return m; } /*最大公倍数*/ long long int gcd(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; return m / lcm(m, n) * n; } /*逆元計算*/ long long int modinv(long long a, long long m) { long long int b = m, u = 1, v = 0; while (b) { long long int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // index が条件を満たすかどうか vector<long long int> meguru; bool isOK(int index, int key) { if (meguru[index] >= key) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_search(int key) { int left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)meguru.size(); // 「index = // a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { long long int n, k; cin >> n >> k; if (n <= k) { cout << min(k - n, n); return 0; } else { long long int c = n; n = n % k; cout << min(n, k - n); } }
delete
110
111
110
110
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; N = N % K; if (K / 2 < N) { N = abs(N - K); } cout << N << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; N = N % K; if (K / 2 < N) { N = abs(N - K); } cout << N << endl; }
replace
3
4
3
4
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, x, n) for (int i = x; i < n; i++) using namespace std; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; const int mod = 1'000'000'007; ll factor(ll n, ll k) { ll x = abs(n - k); if (x > n) { return n; } return factor(x, k); } int main() { ll n, k; cin >> n >> k; if (n % k == 0) { cout << 0 << endl; return 0; } ll ans = factor(n, k); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, x, n) for (int i = x; i < n; i++) using namespace std; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; const int mod = 1'000'000'007; ll factor(ll n, ll k) { ll x = abs(n - k); if (x > n) { return n; } return factor(x, k); } int main() { ll n, k; cin >> n >> k; if (n % k == 0) { cout << 0 << endl; return 0; } ll x = n % k; ll y = abs(x - k); ll z = min(x, y); cout << z << endl; return 0; }
replace
24
26
24
28
TLE
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <cstdlib> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; int main() { ll N, K; cin >> N >> K; ll x; int i = 2; while (i) { if (N - K < 0) { i--; } x = N; N = labs(N - K); } x <= N ? cout << x : cout << N; }
#include <algorithm> #include <cstdlib> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; int main() { ll N, K; cin >> N >> K; ll x; int i = 2; N = N % K; while (i) { if (N - K < 0) { i--; } x = N; N = labs(N - K); } x <= N ? cout << x : cout << N; }
insert
14
14
14
15
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; if (K == 1) { cout << 0 << endl; return 0; } while (1) { if (N < abs(N - K)) break; N = abs(N - K); } cout << N << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; N %= K; cout << min(N, abs(N - K)) << endl; }
replace
6
17
6
8
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } constexpr int mod = 1e9 + 7; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } friend ostream &operator<<(ostream &os, const mint &a) { return (os << a.x); } }; struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; int main() { ll n, k; cin >> n >> k; while (n > abs(n - k)) { n = abs(n - k); } cout << n << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } constexpr int mod = 1e9 + 7; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } friend ostream &operator<<(ostream &os, const mint &a) { return (os << a.x); } }; struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; int main() { ll n, k; cin >> n >> k; if (n > k) n %= k; while (n > abs(n - k)) { n = abs(n - k); } cout << n << endl; }
insert
78
78
78
81
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; while (true) { long long oldN = N; N = min(N, abs(N - K)); if (oldN == N) { break; } } cout << N; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; long long amari = N % K; long long ans = min(amari, K - amari); cout << ans; }
replace
5
13
5
10
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define BIGINF (int)4e18 + 7 #define MOD7 1000000007 #define MOD9 1e9 + 9 #define INF (int)2e9 + 7 #define SCD(t) scanf("%d", &t) #define SCLD(t) scanf("%ld", &t) #define SCLLD(t) scanf("%lld", &t) #define SCC(t) scanf("%c", &t) #define SCS(t) scanf("%s", t) #define SCF(t) scanf("%f", &t) #define SCLF(t) scanf("%lf", &t) #define MEM(a, b) memset(a, (b), sizeof(a)) typedef long long ll; typedef long double ld; typedef string str; typedef double d; typedef unsigned u; typedef unsigned long long ull; int main() { #ifndef ONLINE_JUDGE freopen("inputf.txt", "r", stdin); freopen("outputf.txt", "w", stdout); #endif long long n, k; SCLLD(n); SCLLD(k); if (n == 0) { printf("0"); } else { long long ans = n % k; ans = min(ans, abs(ans - k)); printf("%lld", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; #define BIGINF (int)4e18 + 7 #define MOD7 1000000007 #define MOD9 1e9 + 9 #define INF (int)2e9 + 7 #define SCD(t) scanf("%d", &t) #define SCLD(t) scanf("%ld", &t) #define SCLLD(t) scanf("%lld", &t) #define SCC(t) scanf("%c", &t) #define SCS(t) scanf("%s", t) #define SCF(t) scanf("%f", &t) #define SCLF(t) scanf("%lf", &t) #define MEM(a, b) memset(a, (b), sizeof(a)) typedef long long ll; typedef long double ld; typedef string str; typedef double d; typedef unsigned u; typedef unsigned long long ull; int main() { // #ifndef ONLINE_JUDGE // freopen("inputf.txt", "r", stdin); // freopen("outputf.txt", "w", stdout); // #endif ll n, k; SCLLD(n); SCLLD(k); if (n == 0) { printf("0"); } else { long long ans = n % k; ans = min(ans, abs(ans - k)); printf("%lld", ans); } return 0; }
replace
22
27
22
27
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using p = pair<int, int>; int main() { ll n, k; cin >> n >> k; ll ans = 0; k = k % n; ll ans_2 = 0; ans_2 = abs(n - k); ans = min(ans_2, min(n, k)); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using p = pair<int, int>; int main() { ll n, k; cin >> n >> k; ll ans = 0; n = n % k; ans = min(n, k - n); cout << ans << endl; return 0; }
replace
11
15
11
13
0
p02719
C++
Runtime Error
#include <iostream> #include <map> #include <math.h> #include <stdlib.h> #include <string> #include <time.h> using namespace std; int main() { int N, K; int a, b; cin >> N >> K; if (N > K) { a = N % K; b = K - a; if (a <= b) cout << a << endl; else cout << b << endl; } else if (N == K) { cout << 0 << endl; } else { a = N; b = K - N; if (a <= b) cout << a << endl; else cout << b << endl; } return 0; }
#include <iostream> #include <map> #include <math.h> #include <stdlib.h> #include <string> #include <time.h> using namespace std; int main() { long long N, K; long long a, b; cin >> N >> K; if (N > K) { a = N % K; b = K - a; if (a <= b) cout << a << endl; else cout << b << endl; } else if (N == K) { cout << 0 << endl; } else { a = N; b = K - N; if (a <= b) cout << a << endl; else cout << b << endl; } return 0; }
replace
9
11
9
11
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; cout << min(N % K, K - (N % K)); }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N, K; cin >> N >> K; cout << min(N % K, K - (N % K)); }
replace
4
5
4
5
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #include <string> using namespace std; typedef double db; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<ld> vd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef priority_queue<int> pqi; typedef priority_queue<int, vi, greater<int>> mpqi; #define IOS \ std::ios::sync_with_stdio(false); \ cin.tie(0); #define F0R(i, a) for (int i = 0; i < a; i++) #define R0F(i, a) for (int i = a - 1; i >= 0; i--) #define pb push_back #define mp make_pair #define ins insert #define ft front() #define bk back() #define f first #define s second #define trav(a, x) for (auto &a : x) #define ALL(x) (x).begin(), (x).end() const int MOD = 1000000007; const int MX = 2e5 + 2; const ll INF = 1000000000000000000; const ld PI = 4 * atan((ld)1); const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; bool tkmin(int a, int b) { return b < a ? a = b, true : false; } bool tkmax(int a, int b) { return b > a ? a = b, true : false; } int rudiv(int a, int b) { return a / b + !(a % b == 0); } // Output void op(int ok) { cout << ok << endl; } void op(string ok) { cout << ok << endl; } void op(ll ok) { cout << ok << endl; } void op(char ok) { cout << ok << endl; } void op(db ok) { cout << fixed << setprecision(7) << ok << endl; } void op(ld ok) { cout << fixed << setprecision(7) << ok << endl; } void op(pi ok) { cout << ok.f << " " << ok.s << endl; } void op(pl ok) { cout << ok.f << " " << ok.s << endl; } void op(pd ok) { cout << ok.f << " " << ok.s << endl; } // ----------- int n, k; int main() { IOS; cin >> n >> k; op(min(n % k, abs(k - n % k))); return 0; // You should actually read the notes to self. } /* NOTES TO SELF: Int overflow? Array bounds? Edge cases? (n = 1, n = 0) Don't be dumbosity please pace yourself. */
#include <bits/stdc++.h> #include <iostream> #include <string> using namespace std; typedef double db; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<ld> vd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef priority_queue<int> pqi; typedef priority_queue<int, vi, greater<int>> mpqi; #define IOS \ std::ios::sync_with_stdio(false); \ cin.tie(0); #define F0R(i, a) for (int i = 0; i < a; i++) #define R0F(i, a) for (int i = a - 1; i >= 0; i--) #define pb push_back #define mp make_pair #define ins insert #define ft front() #define bk back() #define f first #define s second #define trav(a, x) for (auto &a : x) #define ALL(x) (x).begin(), (x).end() const int MOD = 1000000007; const int MX = 2e5 + 2; const ll INF = 1000000000000000000; const ld PI = 4 * atan((ld)1); const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; bool tkmin(int a, int b) { return b < a ? a = b, true : false; } bool tkmax(int a, int b) { return b > a ? a = b, true : false; } int rudiv(int a, int b) { return a / b + !(a % b == 0); } // Output void op(int ok) { cout << ok << endl; } void op(string ok) { cout << ok << endl; } void op(ll ok) { cout << ok << endl; } void op(char ok) { cout << ok << endl; } void op(db ok) { cout << fixed << setprecision(7) << ok << endl; } void op(ld ok) { cout << fixed << setprecision(7) << ok << endl; } void op(pi ok) { cout << ok.f << " " << ok.s << endl; } void op(pl ok) { cout << ok.f << " " << ok.s << endl; } void op(pd ok) { cout << ok.f << " " << ok.s << endl; } // ----------- ll n, k; int main() { IOS; cin >> n >> k; op(min(n % k, abs(k - n % k))); return 0; // You should actually read the notes to self. } /* NOTES TO SELF: Int overflow? Array bounds? Edge cases? (n = 1, n = 0) Don't be dumbosity please pace yourself. */
replace
56
57
56
57
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios::sync_with_stdio(0); ll n, k; cin >> n >> k; if (k == 1 or n == k) cout << 0; else { if (n < k) cout << min(n, k - n); else if (n % k == 0) cout << 0; else { set<ll> xs; while (true) { if (xs.count(n)) { cout << *xs.begin(); return 0; } xs.insert(n); n = abs(n - k); } } } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios::sync_with_stdio(0); ll n, k; cin >> n >> k; if (k == 1 or n == k) cout << 0; else { if (n < k) cout << min(n, k - n); else if (n % k == 0) cout << 0; else cout << min(n % k, k - (n % k)); } cout << endl; return 0; }
replace
18
29
18
20
TLE
p02719
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { long long n, k; cin >> n >> k; long long tmp = abs(n - k); if (n % k == 0) n = 0; while (n > tmp) { n = tmp; tmp = abs(n - k); } cout << n << endl; return 0; }
#include <cmath> #include <iostream> using namespace std; int main() { long long n, k; cin >> n >> k; n = n % k; long long ans = min(n, k - n); cout << ans << endl; return 0; }
replace
8
16
8
11
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; // 10^19 < 9223372036854775807 typedef unsigned long long ull; // 10^20 < 18446744073709551615 #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define FORD(i, a, b) for (ll i = a; i >= ll(b); i--) #define FORA(i, I) for (const auto &i : I) #define ALL(x) x.begin(), x.end() #define SIZE(x) ll(x.size()) #define MOD 1000000007 int main(void) { ll N, K; cin >> N >> K; while (N >= abs(N - K)) { N = abs(N - K); } cout << N << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; // 10^19 < 9223372036854775807 typedef unsigned long long ull; // 10^20 < 18446744073709551615 #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define FORD(i, a, b) for (ll i = a; i >= ll(b); i--) #define FORA(i, I) for (const auto &i : I) #define ALL(x) x.begin(), x.end() #define SIZE(x) ll(x.size()) #define MOD 1000000007 int main(void) { ll N, K; cin >> N >> K; cout << min(N % K, K - (N % K)) << endl; return 0; }
replace
18
24
18
19
TLE
p02719
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main(void) { long long N, K; cin >> N >> K; long long ans = N; while (1) { if (ans >= K) { ans = ans - K; } else { break; } } ans = min(ans, K - ans); cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main(void) { long long N, K; cin >> N >> K; long long ans = N % K; ans = min(ans, K - ans); cout << ans << endl; return 0; }
replace
7
15
7
8
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long int #define ld long double #define ff first #define ss second #define mp make_pair #define pb push_back #define si set<int> #define vi vector<int> #define pii pair<int, int> #define vpii vector<pii> #define vpp vector<pair<int, pii>> #define mii map<int, int> #define mpi map<pii, int> #define msi map<string, int> #define loop(i, s, e) for (int i = s; i < e; i++) #define rloop(i, e, s) for (int i = e; i >= s; i--) #define mset(a, f) memset(a, f, sizeof(a)) #define spi set<pii> #define endl "\n" #define M 1000000007 #define sz(x) ((int)x.size()) #define all(p) p.begin(), p.end() #define que_max priority_queue<int> #define que_min priority_queue<int, vi, greater<int>> #define bug(...) __f(#__VA_ARGS__, __VA_ARGS__) #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define Print(a, x, y) \ for (int i = x; i < y; i++) \ cout << a[i] << " "; \ cout << endl inline int power(int a, int b) { int x = 1; while (b) { if (b & 1) x *= a; a *= a; b >>= 1; } return x; } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } const int N = 2e5 + 3; void solve() { int n, k; cin >> n >> k; set<int> s; int ans = 1e18; if (k == 1) { cout << 0; return; } else { while (s.find(n) == s.end()) { s.insert(n); n = abs(n - k); ans = min(ans, n); } } cout << ans; return; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cout << setprecision(9) << fixed; clock_t z = clock(); int t = 1; // cin >> t; while (t--) { solve(); } cerr << "Total Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define ld long double #define ff first #define ss second #define mp make_pair #define pb push_back #define si set<int> #define vi vector<int> #define pii pair<int, int> #define vpii vector<pii> #define vpp vector<pair<int, pii>> #define mii map<int, int> #define mpi map<pii, int> #define msi map<string, int> #define loop(i, s, e) for (int i = s; i < e; i++) #define rloop(i, e, s) for (int i = e; i >= s; i--) #define mset(a, f) memset(a, f, sizeof(a)) #define spi set<pii> #define endl "\n" #define M 1000000007 #define sz(x) ((int)x.size()) #define all(p) p.begin(), p.end() #define que_max priority_queue<int> #define que_min priority_queue<int, vi, greater<int>> #define bug(...) __f(#__VA_ARGS__, __VA_ARGS__) #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define Print(a, x, y) \ for (int i = x; i < y; i++) \ cout << a[i] << " "; \ cout << endl inline int power(int a, int b) { int x = 1; while (b) { if (b & 1) x *= a; a *= a; b >>= 1; } return x; } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } const int N = 2e5 + 3; void solve() { int n, k; cin >> n >> k; int ans = min(n % k, k - (n % k)); cout << ans; return; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cout << setprecision(9) << fixed; clock_t z = clock(); int t = 1; // cin >> t; while (t--) { solve(); } cerr << "Total Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC); return 0; }
replace
63
77
63
64
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; if (n % k == 0 || n == k) { cout << "0"; return 0; } else { if (k > 2 * n) { cout << n; } else { while (1) { long long m = n; n = abs(n - k); if (m < n) { cout << m; return 0; } } } } }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; cout << min(n % k, abs(n % k - k)); }
replace
6
23
6
7
TLE
p02719
C++
Time Limit Exceeded
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < int(b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i) #define REP(i, n) FOR(i, 0, n) #define REP1(i, n) FOR(i, 1, int(n) + 1) #define RREP(i, n) RFOR(i, 0, n) #define RREP1(i, n) RFOR(i, 1, int(n) + 1) #define ALL(c) begin(c), end(c) int _ = ( #ifndef LOCAL std::cin.tie(nullptr), std::ios::sync_with_stdio(false), #endif std::cout.precision(10), std::cout.setf(std::ios::fixed)); using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T> using vec = std::vector<T>; using namespace std; int main() { ll N, K; cin >> N >> K; if (K == 1) { cout << 0 << endl; return 0; } ll x = N; while (K < 2 * x) { x = abs(x - K); } cout << x << endl; return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < int(b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i) #define REP(i, n) FOR(i, 0, n) #define REP1(i, n) FOR(i, 1, int(n) + 1) #define RREP(i, n) RFOR(i, 0, n) #define RREP1(i, n) RFOR(i, 1, int(n) + 1) #define ALL(c) begin(c), end(c) int _ = ( #ifndef LOCAL std::cin.tie(nullptr), std::ios::sync_with_stdio(false), #endif std::cout.precision(10), std::cout.setf(std::ios::fixed)); using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T> using vec = std::vector<T>; using namespace std; int main() { ll N, K; cin >> N >> K; const ll r = N % K; const ll s = K - r; cout << (r < s ? r : s) << endl; return 0; }
replace
26
36
26
29
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < int(n); ++i) using namespace std; template <class A> void pr(A a) { cout << a << endl; } template <class A, class B> void pr(A a, B b) { cout << a << " "; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << " "; pr(b, c); } template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) { cout << a << " "; pr(b, c, d); } typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; int INF = numeric_limits<int>::max(); // for(int j=0;j<N;++j) {} int main(void) { ll n, k; cin >> n >> k; ll res = n; while (abs(res - k) < res) { res = abs(res - k); } pr(res); return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < int(n); ++i) using namespace std; template <class A> void pr(A a) { cout << a << endl; } template <class A, class B> void pr(A a, B b) { cout << a << " "; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << " "; pr(b, c); } template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) { cout << a << " "; pr(b, c, d); } typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; int INF = numeric_limits<int>::max(); // for(int j=0;j<N;++j) {} int main(void) { ll n, k; cin >> n >> k; ll res; ll cnt = n / k; res = n - k * cnt; res = min(res, abs(res - k)); pr(res); return 0; }
replace
25
29
25
29
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; n = n % k; if (n == 0 || (n < k && n < abs(n - k))) { cout << n << endl; return 0; } else cout << abs(n - k) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; n = n % k; if (n == 0 || (n < k && n < abs(n - k))) { cout << n << endl; return 0; } else cout << abs(n - k) << endl; return 0; }
replace
5
6
5
6
0
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { long long a, b; cin >> a >> b; long long m = abs(a - b); long long i = 1; for (;;) { if (m < abs(a - i * b)) break; else { m = abs(a - i * b); i++; continue; } } cout << min(a, m) << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { long long a, b; cin >> a >> b; long long m = min(abs(b - (a % b)), a % b); cout << min(a, m) << endl; return 0; }
replace
8
19
8
9
TLE
p02719
C++
Runtime Error
// vector<vector<int>> data(3, // vector<int>(4));//int型の2次元配列(3×4要素の)の宣言 int64_t a; 10のi乗pow(10, // i); #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main() { /* code */ int N, K; cin >> N >> K; cout << min(N % K, K - N % K) << endl; return 0; }
// vector<vector<int>> data(3, // vector<int>(4));//int型の2次元配列(3×4要素の)の宣言 int64_t a; 10のi乗pow(10, // i); #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main() { int64_t n, k; cin >> n >> k; // int a; cout << min(n % k, abs(n % k - k)) << endl; // a = n % k; // if(a<=abs(a-k))cout<< a <<endl; // else cout<<abs(a-k)<<endl; }
replace
10
15
10
18
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; int t = 0; if (k == 1) { cout << 0 << endl; return 0; } while (t == 0) { if (n > abs(n - k)) { n = abs(n - k); } else { break; } } cout << n << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; int t = 0; if (k == 1) { cout << 0 << endl; return 0; } n = n % k; while (t == 0) { if (n > abs(n - k)) { n = abs(n - k); } else { break; } } cout << n << endl; }
insert
12
12
12
13
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, k, m; cin >> n >> k; while (true) { m = abs(n - k); if (m >= n) { break; } else { n = m; } } cout << n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, k, m; cin >> n >> k; if (n > k) { n %= k; } while (true) { m = abs(n - k); if (m >= n) { break; } else { n = m; } } cout << n << endl; return 0; }
insert
8
8
8
12
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; if (K == 1) { cout << 0 << endl; return 0; } long long ans = N; while (1) { long long tmp = llabs(llabs(N) - llabs(K)); N = tmp; if (N < ans) { ans = N; } else { break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; if (K == 1) { cout << 0 << endl; return 0; } N = N % K; long long ans = N; while (1) { long long tmp = llabs(llabs(N) - llabs(K)); N = tmp; if (N < ans) { ans = N; } else { break; } } cout << ans << endl; }
insert
11
11
11
13
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; unsigned long long k, n; int main() { cin >> n >> k; if (max(n, k) % min(n, k) != 0) if (n > k) cout << k - n % k; else cout << max(n, k) - min(n, k); if (max(n, k) % min(n, k) == 0) if (n < k) cout << n; else cout << 0; }
#include <bits/stdc++.h> using namespace std; unsigned long long k, n; int main() { cin >> n >> k; if (n == 0) cout << 0, exit(0); n %= k; cout << min(n, k - n); }
replace
5
15
5
9
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << min(n % k, k - n % k); }
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n, k; cin >> n >> k; cout << min(n % k, k - n % k); }
replace
3
4
3
4
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k; int main() { cin >> n >> k; cout << min(n % k, k - (n % k)) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n >> k; cout << min(n % k, k - (n % k)) << endl; return 0; }
replace
2
3
2
5
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (a % b == 0) { cout << 0 << endl; } else if (a % b <= b - a % b) { cout << a % b << endl; } else cout << b - a % b << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; if (a % b == 0) { cout << 0 << endl; } else if (a % b <= b - a % b) { cout << a % b << endl; } else cout << b - a % b << endl; }
replace
3
4
3
4
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long x, k; cin >> x >> k; long long remainder = max(x, k) % min(x, k); long long ans = min(remainder, k - remainder); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long x, k; cin >> x >> k; long long remainder = x % k; long long ans = min(remainder, k - remainder); cout << ans << endl; return 0; }
replace
7
8
7
8
0
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; int main() { long long n, k; vector<long long> v; cin >> n >> k; long long m = n; v.push_back(n); bool flag = 1; while (1) { n = abs(n - k); m = min(n, m); for (int i = 0; i < v.size(); i++) { if (n == v[i]) flag = 0; } if (flag == 0) break; else v.push_back(n); } cout << m << endl; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; int main() { long long n, k; vector<long long> v; cin >> n >> k; long long m = n; v.push_back(n); bool flag = 1; while (1) { if (n > k) n = n % k; else n = abs(n - k); m = min(n, m); for (int i = 0; i < v.size(); i++) { if (n == v[i]) flag = 0; } if (flag == 0) break; else v.push_back(n); } cout << m << endl; }
replace
20
21
20
24
TLE
p02719
C++
Runtime Error
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> #define MOD (1000000007) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { ll maxv = max(a, b); ll minv = min(a, b); if (maxv % minv == 0) return minv; else return gcd(maxv - minv, minv); } int main() { int N, K; cin >> N >> K; cout << min(N % K, K - (N % K)) << endl; return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> #define MOD (1000000007) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { ll maxv = max(a, b); ll minv = min(a, b); if (maxv % minv == 0) return minv; else return gcd(maxv - minv, minv); } int main() { ll N, K; cin >> N >> K; cout << min(N % K, K - (N % K)) << endl; return 0; }
replace
27
28
27
28
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define endl '\n' using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long int n, k, min; cin >> n >> k; if (n % k == 0) { cout << 0; } else { do { min = n; n = abs(n - k); } while (n < min); cout << min; } // system("pause"); return 0; }
#include <bits/stdc++.h> #define endl '\n' using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long int n, k, min; cin >> n >> k; if (n % k == 0) { cout << 0; } else { n %= k; do { min = n; n = abs(n - k); } while (n < min); cout << min; } // system("pause"); return 0; }
insert
13
13
13
14
TLE
p02719
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; void Main() { long long N, K; cin >> N >> K; long long x = N; long long tmp = abs(N - K); bool isExist = (x > tmp); while (isExist) { x = tmp; tmp = abs(tmp - K); if (x <= tmp) { break; } } cout << x << endl; } int main() { std::cout << std::fixed << std::setprecision(15); Main(); }
#include "bits/stdc++.h" using namespace std; void Main() { long long N, K; cin >> N >> K; cout << min(N % K, abs(K - N % K)) << endl; } int main() { std::cout << std::fixed << std::setprecision(15); Main(); }
replace
6
17
6
8
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { const int INF = 1e9 + 10; long long N, K; cin >> N >> K; int chk = 0; long long min = INF; N = N - K * (N / K); while (chk == 0) { N = abs(N - K); if (N == min) chk++; if (N < min) min = N; } cout << min << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { const long long INF = 1e18 + 10; long long N, K; cin >> N >> K; int chk = 0; long long min = INF; N = N - K * (N / K); while (chk == 0) { N = abs(N - K); if (N == min) chk++; if (N < min) min = N; } cout << min << endl; }
replace
5
6
5
6
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define NDEBUG #include <cassert> typedef long long ll; typedef long double Double; typedef unsigned long long ull; typedef pair<int, int> ii; typedef pair<ll, ll> llll; typedef pair<double, double> dd; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<llll> vllll; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<double> vd; typedef vector<long double> vD; #define sz(a) int((a).size()) #define pb push_back #define eb emplace_back #define FOR(var, from, to) for (int var = (from); var <= (to); ++var) #define rep(var, n) for (int var = 0; var < (n); ++var) #define rep1(var, n) for (int var = 1; var <= (n); ++var) #define repC2(vari, varj, n) \ for (int vari = 0; vari < (n)-1; ++vari) \ for (int varj = vari + 1; varj < (n); ++varj) #define repC3(vari, varj, vark, n) \ for (int vari = 0; vari < (n)-2; ++vari) \ for (int varj = vari + 1; varj < (n)-1; ++varj) \ for (int vark = varj + 1; vark < (n); ++vark) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) #define found(s, e) ((s).find(e) != (s).end()) #define mset(arr, val) memset(arr, val, sizeof(arr)) #define mid(x, y) ((x) + ((y) - (x)) / 2) #define IN(x, a, b) ((a) <= (x) && (x) <= (b)) #define cons make_pair #define clamp(v, lo, hi) min(max(v, lo), hi) #define ABS(x) max((x), -(x)) template <typename T1, typename T2> inline void amin(T1 &a, T2 const &b) { if (a > b) a = b; } template <typename T1, typename T2> inline void amax(T1 &a, T2 const &b) { if (a < b) a = b; } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } inline ll square(ll x) { return x * x; } inline ll gcd(ll a, ll b) { while (a) swap(a, b %= a); return b; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; } template <typename T> int find_left(vector<T> &v, T elem) { return (int)(upper_bound(v.begin(), v.end(), elem) - v.begin()) - 1; } template <typename T> int find_right(vector<T> &v, T elem) { return (int)(lower_bound(v.begin(), v.end(), elem) - v.begin()); } const ll MOD = 1000000007LL; inline ll ADD(ll x, ll y) { return (x + y) % MOD; } inline ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; } inline ll MUL(ll x, ll y) { return x * y % MOD; } inline ll POW(ll x, ll e) { ll v = 1; for (; e; x = MUL(x, x), e >>= 1) if (e & 1) v = MUL(v, x); return v; } inline ll INV(ll y) { /*assert(y%MOD!=0);*/ return POW(y, MOD - 2); } inline ll DIV(ll x, ll y) { return MUL(x, INV(y)); } #define INTSPACE 12 char _buf[INTSPACE * 1000000 + 3]; int loadint() { if (fgets(_buf, INTSPACE + 3, stdin) == NULL) return 0; return atoi(_buf); } int loadvec(vector<int> &v, int N = -1) { if (N == 0) { v.clear(); return 0; } if (N == -1) { N = loadint(); if (N == 0) return 0; } int bufsize = INTSPACE * N + 3; if (fgets(_buf, bufsize, stdin) == NULL) return 0; v.resize(N); int i = 0; bool last = false; for (char *p = &_buf[0];;) { char *q = p; while (*q > ' ') ++q; if (*q == 0x0D || *q == 0x0A) last = true; *q = 0; v[i++] = atoi(p); if (last || i == N) break; p = q + 1; } return i; } void read_cr() { fgets(_buf, 256, stdin); } void horizontal(vector<int> &v) { int L = v.size(); for (int i = 0; i < L; ++i) { printf("%d%c", v[i], (i == L - 1) ? '\n' : ' '); } } void horizontall(vector<long long> &v) { int L = v.size(); for (int i = 0; i < L; ++i) { printf("%lld%c", v[i], (i == L - 1) ? '\n' : ' '); } } ll f(ll x, ll y) { return ABS(x - y); } ll solve(ll N, ll K) { if (N > K) N %= K; ll ans = N; rep(i, N) { N = f(N, K); amin(ans, N); } return ans; } int main() { ll N, K; cin >> N >> K; cout << solve(N, K) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define NDEBUG #include <cassert> typedef long long ll; typedef long double Double; typedef unsigned long long ull; typedef pair<int, int> ii; typedef pair<ll, ll> llll; typedef pair<double, double> dd; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<llll> vllll; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<double> vd; typedef vector<long double> vD; #define sz(a) int((a).size()) #define pb push_back #define eb emplace_back #define FOR(var, from, to) for (int var = (from); var <= (to); ++var) #define rep(var, n) for (int var = 0; var < (n); ++var) #define rep1(var, n) for (int var = 1; var <= (n); ++var) #define repC2(vari, varj, n) \ for (int vari = 0; vari < (n)-1; ++vari) \ for (int varj = vari + 1; varj < (n); ++varj) #define repC3(vari, varj, vark, n) \ for (int vari = 0; vari < (n)-2; ++vari) \ for (int varj = vari + 1; varj < (n)-1; ++varj) \ for (int vark = varj + 1; vark < (n); ++vark) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) #define found(s, e) ((s).find(e) != (s).end()) #define mset(arr, val) memset(arr, val, sizeof(arr)) #define mid(x, y) ((x) + ((y) - (x)) / 2) #define IN(x, a, b) ((a) <= (x) && (x) <= (b)) #define cons make_pair #define clamp(v, lo, hi) min(max(v, lo), hi) #define ABS(x) max((x), -(x)) template <typename T1, typename T2> inline void amin(T1 &a, T2 const &b) { if (a > b) a = b; } template <typename T1, typename T2> inline void amax(T1 &a, T2 const &b) { if (a < b) a = b; } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } inline ll square(ll x) { return x * x; } inline ll gcd(ll a, ll b) { while (a) swap(a, b %= a); return b; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; } template <typename T> int find_left(vector<T> &v, T elem) { return (int)(upper_bound(v.begin(), v.end(), elem) - v.begin()) - 1; } template <typename T> int find_right(vector<T> &v, T elem) { return (int)(lower_bound(v.begin(), v.end(), elem) - v.begin()); } const ll MOD = 1000000007LL; inline ll ADD(ll x, ll y) { return (x + y) % MOD; } inline ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; } inline ll MUL(ll x, ll y) { return x * y % MOD; } inline ll POW(ll x, ll e) { ll v = 1; for (; e; x = MUL(x, x), e >>= 1) if (e & 1) v = MUL(v, x); return v; } inline ll INV(ll y) { /*assert(y%MOD!=0);*/ return POW(y, MOD - 2); } inline ll DIV(ll x, ll y) { return MUL(x, INV(y)); } #define INTSPACE 12 char _buf[INTSPACE * 1000000 + 3]; int loadint() { if (fgets(_buf, INTSPACE + 3, stdin) == NULL) return 0; return atoi(_buf); } int loadvec(vector<int> &v, int N = -1) { if (N == 0) { v.clear(); return 0; } if (N == -1) { N = loadint(); if (N == 0) return 0; } int bufsize = INTSPACE * N + 3; if (fgets(_buf, bufsize, stdin) == NULL) return 0; v.resize(N); int i = 0; bool last = false; for (char *p = &_buf[0];;) { char *q = p; while (*q > ' ') ++q; if (*q == 0x0D || *q == 0x0A) last = true; *q = 0; v[i++] = atoi(p); if (last || i == N) break; p = q + 1; } return i; } void read_cr() { fgets(_buf, 256, stdin); } void horizontal(vector<int> &v) { int L = v.size(); for (int i = 0; i < L; ++i) { printf("%d%c", v[i], (i == L - 1) ? '\n' : ' '); } } void horizontall(vector<long long> &v) { int L = v.size(); for (int i = 0; i < L; ++i) { printf("%lld%c", v[i], (i == L - 1) ? '\n' : ' '); } } ll f(ll x, ll y) { return ABS(x - y); } ll solve(ll N, ll K) { if (N > K) N %= K; ll ans = N; rep(i, 10) { N = f(N, K); amin(ans, N); } return ans; } int main() { ll N, K; cin >> N >> K; cout << solve(N, K) << endl; return 0; }
replace
161
162
161
162
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; while (N > abs(N - K)) { N = abs(N - K); } cout << N << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; N %= K; while (N > abs(N - K)) { N = abs(N - K); } cout << N << endl; }
insert
6
6
6
7
TLE
p02719
C++
Time Limit Exceeded
#include <iostream> #include <map> #include <math.h> using namespace std; int main() { long long n, k; cin >> n >> k; map<long long, bool> mp; long long ans = n; while (!mp[abs(n - k)]) { mp[abs(n - k)] = 1; ans = min(ans, abs(n - k)); n = abs(n - k); } cout << ans; }
#include <iostream> #include <map> #include <math.h> using namespace std; int main() { long long n, k; cin >> n >> k; n %= k; cout << min(n, abs(k - n)); }
replace
8
16
8
10
TLE
p02719
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define FastIO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define nl "\n" #define sp " " #define int long long int32_t main() { FastIO; int n, k; cin >> n >> k; if (k > n / 2) k = abs(n - k); cout << n % k << nl; return 0; }
#include "bits/stdc++.h" using namespace std; #define FastIO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define nl "\n" #define sp " " #define int long long int32_t main() { FastIO; int n, k; cin >> n >> k; int x = n / k; int y = x + 1; x *= k; y *= k; int ans = min(abs(x - n), abs(y - n)); cout << ans << nl; return 0; }
replace
15
18
15
21
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; ll diff = abs(n - k); ll mod = n % diff; if (mod == k) { cout << 0 << endl; } else { cout << mod << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; ll mod = n % k; ll modEdit = k - mod; cout << min(mod, modEdit) << endl; return 0; }
replace
11
18
11
14
0
p02719
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long const ll maxn = 1005; const ll mod = 1e9 + 7; const ll inf = 1 << 30; int main() { int n, k; cin >> n >> k; int x = n % k; printf("%d", min(x, abs(x - k))); }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long const ll maxn = 1005; const ll mod = 1e9 + 7; const ll inf = 1 << 30; int main() { ll n, k; scanf("%lld%lld", &n, &k); ll x = n % k; printf("%lld", min(x, abs(x - k))); }
replace
18
22
18
22
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; if (n == k) { cout << 0 << endl; } else if (n < k) { cout << min(n, k - n) << endl; } else { bool f = true; while (f) { n = n - k; if (n <= k) { f = false; } } cout << min(n, k - n) << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; if (n == k) { cout << 0 << endl; } else if (n < k) { cout << min(n, k - n) << endl; } else { cout << min(n % k, k - n % k) << endl; } }
replace
12
20
12
13
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> typedef int ll; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define clr(a, h) memset(a, (h), sizeof(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define F first #define S second #define f first #define s second #define fore(i, b, e) for (ll i = (ll)b; i < (ll)e; i++) #define forr(i, b, e) for (ll i = (ll)b; i < (ll)e; i++) ll faster_in() { ll r = 0, c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == '-') return -faster_in(); for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar()) ; return r; } using namespace std; // using namespace __gnu_pbds; typedef double lldb; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<ll> vll; // typedef // tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; const ll INF = ll(1e9 + 7); const lldb PI = acos(-1); #define tam 320000 const ll MOD = 1e9 + 7; int main() { ll a, b; cin >> a >> b; if (a % b == 0) cout << 0 << endl; else { a %= b; cout << min(b - a, a) << endl; } } // PLUS ULTRA!
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define clr(a, h) memset(a, (h), sizeof(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define F first #define S second #define f first #define s second #define fore(i, b, e) for (ll i = (ll)b; i < (ll)e; i++) #define forr(i, b, e) for (ll i = (ll)b; i < (ll)e; i++) ll faster_in() { ll r = 0, c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == '-') return -faster_in(); for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar()) ; return r; } using namespace std; // using namespace __gnu_pbds; typedef double lldb; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<ll> vll; // typedef // tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; const ll INF = ll(1e9 + 7); const lldb PI = acos(-1); #define tam 320000 const ll MOD = 1e9 + 7; int main() { ll a, b; cin >> a >> b; if (a % b == 0) cout << 0 << endl; else { a %= b; cout << min(b - a, a) << endl; } } // PLUS ULTRA!
replace
3
4
3
4
0
p02719
C++
Runtime Error
/* Author - thiolhub */ #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define db double #define pi 3.1415926535897932384626 #define PI acos(-1.0) #define endl "\n" #define mod 1000000007 #define mk make_pair #define pb push_back #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define ps(x, y) fixed << setprecision(y) << x #define w(t) \ ll t; \ cin >> t; \ while (t--) #define sc(a) scanf("%lld", &a); #define pr(a) printf("%lld\n", a) #define f(i, a, n) for (ll i = a; i < n; i++) #define m(a) memset(a, 0, sizeof(a)) #define FastIO \ ios_base::sync_with_stdio(0); \ cin.tie(0), cout.tie(0) int main() { FastIO; int n, k; cin >> n >> k; cout << min(n % k, k - (n % k)); return 0; }
/* Author - thiolhub */ #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define db double #define pi 3.1415926535897932384626 #define PI acos(-1.0) #define endl "\n" #define mod 1000000007 #define mk make_pair #define pb push_back #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define ps(x, y) fixed << setprecision(y) << x #define w(t) \ ll t; \ cin >> t; \ while (t--) #define sc(a) scanf("%lld", &a); #define pr(a) printf("%lld\n", a) #define f(i, a, n) for (ll i = a; i < n; i++) #define m(a) memset(a, 0, sizeof(a)) #define FastIO \ ios_base::sync_with_stdio(0); \ cin.tie(0), cout.tie(0) int main() { FastIO; ll n, k; cin >> n >> k; cout << min(n % k, k - (n % k)); return 0; }
replace
38
39
38
39
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef long double ld; int main() { ll N, K; cin >> N >> K; while (1) { if (N > abs(N - K)) { N = abs(N - K); } else { break; } } cout << N << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef long double ld; int main() { ll N, K; cin >> N >> K; N = N - (N / K) * K; while (1) { if (N > abs(N - K)) { N = abs(N - K); } else { break; } } cout << N << endl; return 0; }
insert
11
11
11
13
TLE
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <stdio.h> #include <string> using namespace std; int main() { long long n, k; cin >> n >> k; while (n > abs(n - k)) { n = abs(n - k); } cout << n << endl; }
#include <algorithm> #include <iostream> #include <stdio.h> #include <string> using namespace std; int main() { long long n, k; cin >> n >> k; n = n % k; while (n > abs(n - k)) { n = abs(n - k); } cout << n << endl; }
insert
10
10
10
11
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define sz(a) int((a).size()) #define int long long #define all(c) c.begin(), c.end() #define FAST ios_base::sync_with_stdio(false), cin.tie(NULL); #define pb push_back #define F first #define S second #define endl "\n" #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) #define bitcnt(n) __builtin_popcountll(n) #define tr(container, s) \ for (auto x : container) { \ cout << x << s; \ } \ cout << endl; #define one(x) cerr << #x << " : " << x << endl; #define two(x, y) cerr << #x << " : " << x << " , " << #y << " : " << y << endl; #define three(x, y, z) \ cerr << #x << " : " << x << " , " << #y << " : " << y << " , " << #z \ << " : " << z << endl; #define PI acos(-1) const int M = 1000000007; const int N = 3e5 + 5; signed main() { int tc, m, i, j; int n, k; cin >> n >> k; if (n % j == 0) { cout << 0 << endl; } else { int x = n / k; int y = x + 1; cout << min(abs(x * k - n), abs(k * y - n)) << endl; } }
#include <bits/stdc++.h> using namespace std; #define sz(a) int((a).size()) #define int long long #define all(c) c.begin(), c.end() #define FAST ios_base::sync_with_stdio(false), cin.tie(NULL); #define pb push_back #define F first #define S second #define endl "\n" #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) #define bitcnt(n) __builtin_popcountll(n) #define tr(container, s) \ for (auto x : container) { \ cout << x << s; \ } \ cout << endl; #define one(x) cerr << #x << " : " << x << endl; #define two(x, y) cerr << #x << " : " << x << " , " << #y << " : " << y << endl; #define three(x, y, z) \ cerr << #x << " : " << x << " , " << #y << " : " << y << " , " << #z \ << " : " << z << endl; #define PI acos(-1) const int M = 1000000007; const int N = 3e5 + 5; signed main() { int tc, m, i, j; int n, k; cin >> n >> k; if (n % k == 0) { cout << 0 << endl; } else { int x = n / k; int y = x + 1; cout << min(abs(x * k - n), abs(k * y - n)) << endl; } }
replace
30
31
30
31
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long n, m; int main() { cin >> n >> m; if (n % m == 0) cout << "0"; else { while (n > abs(n - m)) { n = abs(n - m); // cout<<abs(n-m)<<endl; } cout << n << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m; int main() { cin >> n >> m; if (n % m == 0) cout << "0"; else if (n < m) { if (n < m - n) cout << n; if (n >= m - n) cout << m - n; } else { n %= m; if (n > m - n) { n = m - n; // cout<<abs(n-m)<<endl; } cout << n << endl; } return 0; }
replace
7
10
7
16
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; scanf("%lli%lli", &n, &k); if (n % k == 0) { printf("0\n"); } else { long long int mini; mini = n; while (1) { n = abs(n - k); if (n < mini) { mini = n; } else if (n == mini) { printf("%lli", mini); break; } } } }
#include <bits/stdc++.h> using namespace std; main() { unsigned long long n, k, m, ans; cin >> n >> k; m = n % k; if ((k - m) < m) cout << k - m << '\n'; else cout << m << '\n'; }
replace
2
20
2
10
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll i, j, k, l, m, n, o, p, q, r, s, t, x, a[500], tt = 0; cin >> n >> m; p = (n % m); q = m % n; r = m - p; s = n - q; cout << min({p, q, r, s}) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll i, j, k, l, m, n, o, p, q, r, s, t, x, a[500], tt = 0; cin >> n >> m; p = (n % m); q = m % n; r = m - p; s = n - q; cout << min({p, r}) << endl; return 0; }
replace
12
13
12
13
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) const lint mod = 1e9 + 7; int main() { lint n, k; cin >> n >> k; if (k == 1) { cout << 0 << "\n"; return 0; } lint x = n; while (x > abs(x - k)) { x = abs(x - k); } cout << x << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) const lint mod = 1e9 + 7; int main() { lint n, k; cin >> n >> k; lint x = n % k; while (x > abs(x - k)) { x = abs(x - k); } cout << x << "\n"; return 0; }
replace
27
32
27
28
TLE
p02719
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <tuple> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; int main(int argc, char *argv[]) { int n, k; int left, right; cin >> n >> k; left = n % k; right = left + k; cout << min(right - k, k - left) << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <tuple> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; int main(int argc, char *argv[]) { ll n, k; ll left, right; cin >> n >> k; left = n % k; right = left + k; cout << min(right - k, k - left) << endl; return 0; }
replace
14
16
14
16
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; if (k == 1) n = 0; while (abs(n - k) < n) n = abs(n - k); cout << n; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; n = n % k; if (2 * n > k) cout << abs(n - k); else cout << n; }
replace
6
11
6
11
TLE
p02719
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { long long n, k; cin >> n >> k; while (n > k) { n = n - k; } if (n <= k / 2) { cout << n; } else { n = k - n; cout << n << endl; } return 0; }
#include <iostream> using namespace std; int main() { long long n, k; cin >> n >> k; n = n % k; if (n <= k / 2) { cout << n; } else { n = k - n; cout << n << endl; } return 0; }
replace
7
10
7
8
TLE
p02719
C++
Time Limit Exceeded
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iostream> // cout, endl, cin #include <map> // map #include <math.h> // sqrt #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; int main() { long long N, K; cin >> N >> K; if (K == 1) { N = 0; } while (true) { if (2 * N < K) { break; } if (N < K) { N = K - N; continue; } N -= K; } cout << N << endl; }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iostream> // cout, endl, cin #include <map> // map #include <math.h> // sqrt #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; int main() { long long N, K; cin >> N >> K; N = N % K; if (K < 2 * N) { N = K - N; } cout << N << endl; }
replace
23
35
23
26
TLE
p02719
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; cout << min(n % k, k - n % k); return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { long long n, k; cin >> n >> k; cout << min(n % k, k - n % k); return 0; }
replace
5
6
5
6
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int testcase = 1; // cin>>testcase; for (int p = 0; p < testcase; p++) { ll n = 0, k = 0; cin >> n >> k; cout << min((n) % (abs(n - k)), (n % k)); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int testcase = 1; // cin>>testcase; for (int p = 0; p < testcase; p++) { ll n = 0, k = 0; cin >> n >> k; n = n % k; cout << min(n, abs(n - k)); } return 0; }
replace
12
13
12
14
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define debug(x) cerr << #x << ": " << x << "\n" #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define _sort(a) sort(a.begin(), a.end()) using namespace std; using ll = long long; using vi = vector<int>; using vii = vector<int, int>; int main() { ios::sync_with_stdio(false), cin.tie(0); long long int n, k, d, mn = 1e18; cin >> n >> k; mn = n; if (k == 1) return cout << 0, 0; while (true) { d = abs(n - k); if (d < mn) mn = d; else break; n = mn; } cout << mn; } /* * created: 2020-04-04 17:24:49 */
#include <bits/stdc++.h> #define debug(x) cerr << #x << ": " << x << "\n" #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define _sort(a) sort(a.begin(), a.end()) using namespace std; using ll = long long; using vi = vector<int>; using vii = vector<int, int>; int main() { ios::sync_with_stdio(false), cin.tie(0); long long int n, k, d, mn = 1e18; cin >> n >> k; mn = n = n % k; while (true) { d = abs(n - k); if (d < mn) mn = d; else break; n = mn; } cout << mn; } /* * created: 2020-04-04 17:24:49 */
replace
17
20
17
18
TLE
p02719
C++
Time Limit Exceeded
// Hail god Yato #include <bits/stdc++.h> using namespace std; #define add(x) accumulate(x) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rep(i, a, b) for (int i = a; i < (b); i++) #define hs \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const ll mod = 1000000007; const ll INF = 1e18; const ll MAX = 100001; // // void solve() { ll n, k; cin >> n >> k; while (true) { if (abs(n - k) < n) n = abs(n - k); else break; } cout << n; } int main() { hs; ll t; t = 1; // cin>>t; for (int i = 1; i <= t; i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; }
// Hail god Yato #include <bits/stdc++.h> using namespace std; #define add(x) accumulate(x) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rep(i, a, b) for (int i = a; i < (b); i++) #define hs \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const ll mod = 1000000007; const ll INF = 1e18; const ll MAX = 100001; // // void solve() { ll n, k; cin >> n >> k; ll div = n % k; cout << min(div, k - div); } int main() { hs; ll t; t = 1; // cin>>t; for (int i = 1; i <= t; i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; }
replace
31
38
31
33
TLE
p02719
C++
Runtime Error
/* Author : Nishant Gupta 2.0 */ #include <bits/stdc++.h> #define LL long long int #define getcx getchar_unlocked #define X first #define Y second #define PB push_back #define MP make_pair #define MAX 100005 #define LOG_MAX 20 #define MOD 1000000007 #define INF 0x3f3f3f3f #define INFL (LL(1e18)) #define chk(a) cerr << endl << #a << " : " << a << endl #define chk2(a, b) \ cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl #define chk3(a, b, c) \ cerr << endl \ << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " \ << c << endl #define chk4(a, b, c, d) \ cerr << endl \ << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " \ << c << "\t" << #d << " : " << d << endl #define rep(i, a, n) for (i = a; i < n; i++) #define rev(i, a, n) for (i = a; i >= n; i--) #define MSV(A, a) memset(A, a, sizeof(A)) #define rep_itr(itr, c) for (itr = (c).begin(); itr != (c).end(); itr++) using namespace std; inline void inp(int &n) { n = 0; int ch = getcx(); int sign = 1; while (ch < '0' || ch > '9') { if (ch == '-') sign = -1; ch = getcx(); } while (ch >= '0' && ch <= '9') n = (n << 3) + (n << 1) + ch - '0', ch = getcx(); n = n * sign; } inline void inp1(LL &n) { n = 0; LL ch = getcx(); LL sign = 1; while (ch < '0' || ch > '9') { if (ch == '-') sign = -1; ch = getcx(); } while (ch >= '0' && ch <= '9') n = (n << 3) + (n << 1) + ch - '0', ch = getcx(); n = n * sign; } void solve() { LL n, k; cin >> n >> k; if (n < k) swap(n, k); if (n % k == 0) { cout << k << endl; return; } LL q = (n / k) * k; LL ans = n - q; if (n % k != 0) { ans = min(ans, abs(((n + k - 1) / k) * k - n)); } cout << ans << endl; } int main() { int t = 1; //~cin>>t; while (t--) { solve(); } return 0; }
/* Author : Nishant Gupta 2.0 */ #include <bits/stdc++.h> #define LL long long int #define getcx getchar_unlocked #define X first #define Y second #define PB push_back #define MP make_pair #define MAX 100005 #define LOG_MAX 20 #define MOD 1000000007 #define INF 0x3f3f3f3f #define INFL (LL(1e18)) #define chk(a) cerr << endl << #a << " : " << a << endl #define chk2(a, b) \ cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl #define chk3(a, b, c) \ cerr << endl \ << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " \ << c << endl #define chk4(a, b, c, d) \ cerr << endl \ << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " \ << c << "\t" << #d << " : " << d << endl #define rep(i, a, n) for (i = a; i < n; i++) #define rev(i, a, n) for (i = a; i >= n; i--) #define MSV(A, a) memset(A, a, sizeof(A)) #define rep_itr(itr, c) for (itr = (c).begin(); itr != (c).end(); itr++) using namespace std; inline void inp(int &n) { n = 0; int ch = getcx(); int sign = 1; while (ch < '0' || ch > '9') { if (ch == '-') sign = -1; ch = getcx(); } while (ch >= '0' && ch <= '9') n = (n << 3) + (n << 1) + ch - '0', ch = getcx(); n = n * sign; } inline void inp1(LL &n) { n = 0; LL ch = getcx(); LL sign = 1; while (ch < '0' || ch > '9') { if (ch == '-') sign = -1; ch = getcx(); } while (ch >= '0' && ch <= '9') n = (n << 3) + (n << 1) + ch - '0', ch = getcx(); n = n * sign; } void solve() { LL n, k; cin >> n >> k; LL ans; if (n > k) { ans = min(n % k, abs(k - n % k)); } else if (n < k) { ans = min(n, k - n); } else ans = 0; cout << ans << endl; } int main() { int t = 1; //~cin>>t; while (t--) { solve(); } return 0; }
replace
66
79
66
73
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; using namespace std; int main() { ll n, k; cin >> n >> k; while (true) { ll tmp = n; if (abs(n - k) < n) n = abs(n - k); if (tmp == n) break; } cout << n << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; using namespace std; int main() { ll n, k; cin >> n >> k; if (n >= k) n = n % k; while (true) { ll tmp = n; if (abs(n - k) < n) n = abs(n - k); if (tmp == n) break; } cout << n << endl; return 0; }
insert
8
8
8
11
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; int K; int min; cin >> N >> K; min = N % K; if (min > K - min) { min = K - min; } cout << min << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long N; long K; long min; cin >> N >> K; min = N % K; if (min > K - min) { min = K - min; } cout << min << endl; }
replace
4
7
4
7
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N, K; cin >> N >> K; ll ans = N; while (true) { if (abs(ans - K) >= ans) { break; } ans = abs(ans - K); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N, K; cin >> N >> K; ll ans; ans = min(N % K, abs(N % K - K)); cout << ans << endl; }
replace
6
13
6
8
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; cout << min(N % K, K - N % K) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; cout << min(N % K, K - N % K) << endl; }
replace
3
4
3
4
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n] #define w(x) \ int x; \ cin >> x; \ while (x--) #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { // FIO; c_p_c(); int n, k; cin >> n >> k; cout << min(n % k, k - (n % k)) << endl; }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n] #define w(x) \ int x; \ cin >> x; \ while (x--) #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { FIO; // c_p_c(); int n, k; cin >> n >> k; cout << min(n % k, k - (n % k)) << endl; }
replace
40
42
40
42
0
p02719
C++
Runtime Error
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define dump(x) cout << x << endl typedef int64_t Int; using namespace std; using Graph = vector<vector<Int>>; const double pi = M_PI; const Int MOD = 1000000007; int main() { Int n, k; cin >> n >> k; Int ans = 0; if (n < k) { ans = n; } else { ans = n % (n - k); } cout << ans << endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define dump(x) cout << x << endl typedef int64_t Int; using namespace std; using Graph = vector<vector<Int>>; const double pi = M_PI; const Int MOD = 1000000007; int main() { Int n, k; cin >> n >> k; n = n - (n / k * k); Int ans = min(n, abs(n - k)); cout << ans << endl; return 0; }
replace
14
21
14
16
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; cout << min(N % K, K - N % K) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int N, K; cin >> N >> K; cout << min(N % K, K - N % K) << endl; }
replace
4
5
4
5
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e16; signed main() { int N, K; cin >> N >> K; int ans; if (K == 1) ans = 0; if (N > K) { while (N > K) { N -= K; ans = min(N, K - N); } } if (N < K) ans = min(N, K - N); if (N == K) ans = 0; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e16; signed main() { int N, K; cin >> N >> K; int ans; if (K == 1) ans = 0; if (N > K) { int x = N / K; N -= x * K; ans = min(N, K - N); } if (N < K) ans = min(N, K - N); if (N == K) ans = 0; cout << ans << endl; }
replace
12
16
12
15
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long int N, K; cin >> N >> K; long int num1, num2; if (N > K) { if (N % K == 0) { num1 = 0; num2 = 0; } else { while (N > K) { N = N - K; } num1 = N; N = K - N; num2 = N; } } else if (N < K) { num1 = N; N = K - N; num2 = N; } else { num1 = N; num2 = N - K; } if (num1 <= num2) { cout << num1 << endl; } else { cout << num2 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long int N, K; cin >> N >> K; long int num1, num2; if (N > K) { num1 = N % K; num2 = K - num1; } else if (N < K) { num1 = N; N = K - N; num2 = N; } else { num1 = N; num2 = N - K; } if (num1 <= num2) { cout << num1 << endl; } else { cout << num2 << endl; } }
replace
11
22
11
13
TLE
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <math.h> using namespace std; int main() { long long int a, k, q = -1; for (long long int i = 1; i <= 1000000000000000000; i++) { a = abs(a - k); q = min(q, a); } cout << q << endl; }
#include <algorithm> #include <iostream> #include <math.h> using namespace std; int main() { long long int x, k, x3 = 0, x4 = 0; cin >> x >> k; cout << min(x % k, abs((x % k) - k)) << endl; }
replace
6
12
6
9
TLE
p02719
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { long long int n, t, k; cin >> n >> k; if (n % k == 0) cout << "0" << endl; else { do { t = n; n = n - k; if (n < 0) n = -n; } while (n < t); cout << t << endl; } }
#include <iostream> using namespace std; int main() { long long int n, t, k; cin >> n >> k; if (n % k == 0) cout << "0" << endl; else { n = n % k; do { t = n; n = n - k; if (n < 0) n = -n; } while (n < t); cout << t << endl; } }
insert
8
8
8
9
TLE
p02719
C++
Runtime Error
#include <iostream> using namespace std; int n, k, a; int main() { cin >> n >> k; a = n % k; if (k - a >= a) cout << a; else cout << k - a; return 0; }
#include <iostream> using namespace std; long long n, k, a; int main() { cin >> n >> k; a = n % k; if (k - a >= a) cout << a; else cout << k - a; return 0; }
replace
3
4
3
4
0
p02719
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define ll int64_t #define Rep(i, n) for (ll i = 0; i < n; i++) using namespace std; typedef vector<ll> vec; typedef vector<vec> mat; const ll inf = 1LL << 60; template <class T> inline void chmin(T &a, T b) { if (a > b) { a = b; } } template <class T> inline void chmax(T &a, T b) { if (a < b) { a = b; } } ll GCD(ll a, ll b) { if (a < b) { swap(a, b); } ll r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } ll LCM(ll a, ll b) { ll g = GCD(a, b); return a * b / g; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; ll ans = GCD(N, K); if (ans == K) ans = 0; cout << ans << endl; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define ll int64_t #define Rep(i, n) for (ll i = 0; i < n; i++) using namespace std; typedef vector<ll> vec; typedef vector<vec> mat; const ll inf = 1LL << 60; template <class T> inline void chmin(T &a, T b) { if (a > b) { a = b; } } template <class T> inline void chmax(T &a, T b) { if (a < b) { a = b; } } ll GCD(ll a, ll b) { if (a < b) { swap(a, b); } ll r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } ll LCM(ll a, ll b) { ll g = GCD(a, b); return a * b / g; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; N %= K; cout << min(N, K - N) << "\n"; }
replace
64
69
64
66
0
p02719
C++
Time Limit Exceeded
// C - Replacing Integer #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using ull = unsigned long long; int main() { ll n, k; cin >> n >> k; if (n == 0) cout << 0 << endl; else if (n % k == 0) cout << 0 << endl; else { while (1) { if (n > abs(n - k)) n = abs(n - k); else break; } cout << n << endl; } return 0; }
// C - Replacing Integer #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using ull = unsigned long long; int main() { ll n, k; cin >> n >> k; ll t = n % k; ll ans = min(t, k - t); cout << ans << endl; return 0; }
replace
10
23
10
13
TLE
p02719
C++
Time Limit Exceeded
/** * Dont raise your voice, improve your argument. * --Desmond Tutu */ #include <bits/stdc++.h> using namespace std; const double PI = acos(-1); typedef long long ll; #define int ll #define fori(n) for (int i = 0; i < int(n); i++) #define cins(s) \ string s; \ cin >> s; #define cini(i) \ int i; \ cin >> i; #define cind(d) \ double d; \ cin >> d; #define cinai(a, n) \ vi a(n); \ fori(n) { cin >> a[i]; } #define cinas(s, n) \ vs s(n); \ fori(n) { cin >> s[i]; } #define cinad(a, n) \ vd a(n); \ fori(n) { cin >> a[i]; } typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef vector<double> vd; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<string> vs; void solve() { cini(n); cini(k); int x = n; do { n = x; x = abs(n - k); } while (x < n && n > 0); cout << min(n, x) << endl; } signed main() { cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); }
/** * Dont raise your voice, improve your argument. * --Desmond Tutu */ #include <bits/stdc++.h> using namespace std; const double PI = acos(-1); typedef long long ll; #define int ll #define fori(n) for (int i = 0; i < int(n); i++) #define cins(s) \ string s; \ cin >> s; #define cini(i) \ int i; \ cin >> i; #define cind(d) \ double d; \ cin >> d; #define cinai(a, n) \ vi a(n); \ fori(n) { cin >> a[i]; } #define cinas(s, n) \ vs s(n); \ fori(n) { cin >> s[i]; } #define cinad(a, n) \ vd a(n); \ fori(n) { cin >> a[i]; } typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef vector<double> vd; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<string> vs; void solve() { cini(n); cini(k); int x = n; do { n = x; if (abs(n - k) <= k) x = abs(n - k); else { x = min(n % k, k % n); } } while (x < n && n > 0); cout << min(n, x) << endl; } signed main() { cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); }
replace
49
50
49
54
TLE
p02719
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, k, x, y, f; cin >> n >> k; f = (n / k) + 1; n = n - (k * f); x = -n; y = n + k; if (x < y) { cout << x; } else { cout << y; } }
#include <iostream> using namespace std; int main() { long long int n, k, x, y, f; cin >> n >> k; f = (n / k) + 1; n = n - (k * f); x = -n; y = n + k; if (x < y) { cout << x; } else { cout << y; } }
replace
3
4
3
4
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y; cin >> x >> y; while (x % y == 0) { x /= y; } return x % y == 1; }
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y; cin >> x >> y; long long int ans = min(x % y, y - (x % y)); cout << ans; }
replace
5
9
5
7
0
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; ll mini = n, tmp = 0; if (n % k == 0) { cout << 0 << endl; return 0; } while (1) { mini = min(abs(mini - k), mini); if (mini == tmp) { break; } tmp = mini; } cout << mini << endl; }
#include <algorithm> #include <iostream> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; ll tmp = n % k; ll ans = min(abs(tmp - k), tmp); cout << ans << endl; }
replace
8
21
8
11
TLE