alexjercan/bugnet huggingface dataset:
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  long long int a, b, c, d = INT_MAX, e = 0;
  cin >> a >> b;
  cout << min(a % b, (a % b - b) * -1);
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int a, b, c, d = INT_MAX, e = 0;
  cin >> a >> b;
  cout << min(a % b, (a % b - b) * -1);
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {

  long long int n, k;

  cin >> n;
  cin >> k;

  // cout << k << endl;
  if (k == 1 || (n > k && n % k == 0)) {
    cout << 0 << endl;

  } else {
    if (n > k) {
      n = n % k;
    }
    // vector<long long int> v;

    // v.push_back(n);
    long long int i = 0;
    while (i < 1000000000000000) {
      if (n <= abs(n - k)) {
        break;
      }
      // v.push_back(abs(n-k));
      n = abs(n - k);
      i++;
    }

    // cout << *std::min_element(v.begin(), v.end());
    cout << n;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {

  long long int n, k;

  cin >> n;
  cin >> k;

  // cout << k << endl;
  if (k == 1 && n % k == 0) {
    cout << 0 << endl;

  } else {

    // vector<long long int> v;

    // v.push_back(n);
    long long int i = 0;
    while (i < 1000000000000000) {
      if (n <= abs(n - k)) {
        break;
      }
      // v.push_back(abs(n-k));
      n = abs(n - k);
      i++;
    }

    // cout << *std::min_element(v.begin(), v.end());
    cout << n;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int main() {
  ll N, K;
  cin >> N >> K;
  cout << min(N % K, K - N % K) << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int main() {
  int N, K;
  cin >> N >> K;
  cout << min(N % K, K - N % K) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int long long n, k;
  cin >> n >> k;
  int long long a;
  a = n % k;
  int long long b;
  b = k - a;
  if (a <= b) {
    cout << a << endl;
  } else {
    cout << b << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int long long a;
  a = n % k;
  int long long b;
  b = k - a;
  if (a <= b) {
    cout << a << endl;
  } else {
    cout << b << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main() {
  ll n, k;
  cin >> n >> k;
  cout << min(n % k, k - (n % k));
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main() {
  int n, k;
  cin >> n >> k;
  if (n > k) {
    n = n % k;
  }
  cout << min(n, k - n);
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, K;
  cin >> N >> K;

  long long ans = min(N % K, K - (N % K));
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;

  int ans = min(N % K, K - (N % K));
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define INF 1e18
#define PI 3.141592653589793238
typedef long long ll;
#define N 200010

int main() {
  ll n, k;
  cin >> n >> k;
  // ll ans=INF, tmp=INF;
  n = n % k;
  while (n > (k / 2)) {
    n = abs(k - n);
  }
  cout << n << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define INF 1e18
#define PI 3.141592653589793238
typedef long long ll;
#define N 200010

int main() {
  ll n, k;
  cin >> n >> k;
  // ll ans=INF, tmp=INF;
  if (n % k == 0) {
    cout << 0 << endl;
  } else {
    while (n > (k / 2)) {
      n = abs(k - n);
    }
    cout << n << endl;
  }

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef pair<lli, lli> pii;
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define EPS 1e-6
typedef long long LL;

int main() {
  fast;
  lli n, k;
  cin >> n >> k;
  if (n % k == 0)
    cout << 0;
  else {
    lli rem = n % k;
    cout << min(rem, abs(rem - k));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef pair<lli, lli> pii;
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define EPS 1e-6
typedef long long LL;

LL gcd(LL a, LL b) {
  if (!a)
    return b % mod;
  return gcd(b % a, a) % mod;
}

int main() {
  fast;
  lli n, k;
  cin >> n >> k;
  lli prev;
  if (n % k == 0)
    cout << 0;
  else {
    while (1) {
      prev = abs(n - k);
      n = prev;
      if (abs(n - k) > prev)
        break;
    }
    cout << n;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  if (n > k)
    cout << min(n % k, k - n % k) << endl;
  else
    cout << min(n, k - n) << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  if (n < m)
    cout << n << endl;
  else
    cout << min(n % m, n % (n - m)) << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N, K;
  cin >> N >> K;

  int64_t a = N % K;
  int64_t ans = min(a, K - a);
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;

  int a = N % K;
  int ans = min(a, K - a);
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;
int main() {
  ll n, k, res;
  scanf("%lld%lld", &n, &k);
  ll t = n;
  n %= k;
  if (n == 0)
    cout << 0;
  else {
    for (int i = 1; i < 1e5; i++) {
      t = min(t, abs(n - k));
    }
    cout << t;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;
int main() {
  ll n, k, res;
  scanf("%lld%lld", &n, &k);
  if (n % k == 0) {
    cout << '0';
    return 0;
  }
  while (n > abs(n - k)) {
    n = abs(n - k);
  }
  cout << n;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
#include <map>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = n;
  if (n > k) {
    n = n % k;
    ans = n;
    while (n >= 0) {
      n = n - k;
      if (abs(n) < ans)
        ans = abs(n);
    }
  } else {
    if (k - n < ans)
      ans = k - n;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
#include <map>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = n;
  if (n > k) {
    while (n > 0) {
      n = n - k;
      if (abs(n) < ans)
        ans = abs(n);
    }
  } else {
    if (k - n < ans)
      ans = k - n;
  }
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  long N, K;
  cin >> N >> K;
  N %= K;
  if (N)
    N = N < K - N ? N : K - N;
  cout << N;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  N %= K;
  if (N != 0)
    N = N < K % N ? N : K % N;
  cout << N;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int n, k;
  cin >> n >> k;
  long long int temp;
  temp = n % k;
  if (temp == 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long int> v;

  for (int i = 0; i < 10000000; i++) {
    temp = abs(temp - k);
    v.push_back(temp);
  }
  sort(v.begin(), v.end());

  if (v[0] > n) {
    cout << n << endl;
    return 0;
  }
  cout << v[0] << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int n, k;
  cin >> n >> k;
  long long int temp;
  temp = n % k;
  if (temp == 0) {
    cout << 0 << endl;
    return 0;
  }
  temp = n;
  vector<long long int> v;

  for (int i = 0; i < 100000000; i++) {
    temp = abs(temp - k);
    v.push_back(temp);
  }
  sort(v.begin(), v.end());

  if (v[0] > n) {
    cout << n << endl;
    return 0;
  }
  cout << v[0] << endl;

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll N, K, x, y;
  cin >> N >> K;

  x = N % K;
  y = (x - K) * (-1);

  cout << min(x, y);

  cin >> N;
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  float N, K;
  cin >> N >> K;

  int n, k;

  n = N / 10000000000;
  k = K / 10000000000;

  int x = n % k;

  int y = x - k;
  y = y * (-1);

  if (y > x) {
    cout << x;
  } else {
    cout << y;
  }

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  //    ios::sync_with_stdio(0);
  //    cin.tie(0);
  //    cout.tie(0);
  long long n, k;
  while (~scanf("%lld %lld", &n, &k)) {
    n %= k;
    if (k == 1) {
      printf("0\\n");
    } else {
      long long minn = n;
      while (1) {
        long long flag = abs(minn - k);
        if (flag < minn) {
          minn = flag;
        } else {
          break;
        }
      }

      printf("%lld\\n", minn);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, k;

  cin >> n >> k;
  int t;
  int m = 1;

  while (m) {
    t = n - k;
    if (t < 0) {
      t = -t;
    }
    if (t == n || t == 0) {
      cout << t << endl;
      m = 0;
    } else
      n = t;
  }

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long N, K, t;
  cin >> N >> K;
  t = N % K;
  cout << min(t, K - t);
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int N, K, t;
  cin >> N >> K;
  t = N % K;
  cout << min(t, K - t);
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long n, k;

int main(void) {
  long long ans, t;
  scanf("%lld%lld", &n, &k);
  if (n % k == 0) {
    cout << "0";
    return 0;
  }
  if (n > k)
    n %= k;
  n = min(n, abs(n - k));
  cout << n;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, k;

int main(void) {
  long long ans, t;
  scanf("%lld%lld", &n, &k);
  if (n % k == 0) {
    cout << "0";
    return 0;
  }
  ans = min(n, k);
  t = n / k;
  t++;
  for (int i = 0; i < t; i++) {
    n = abs(n - k);
    ans = min(ans, n);
  }
  cout << ans;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF = 1e9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, k;
  cin >> n >> k;
  n -= (n / k) * k;
  cout << min(n, k - n) << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF = 1e9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n, k;
  cin >> n >> k;
  n -= (n / k) * k;
  cout << min(n, k - n) << '\\n';
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdlib.h>
using namespace std;

long long int N, K, mod, n, a, b;

int main() {
  cin >> N >> K;
  mod = N % K;
  n = (N - mod) / K;
  a = abs(N - n * K);
  b = abs(N - (n + 1) * K);
  if (a < b) {
    cout << a;
  } else {
    cout << b;
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <stdlib.h>
using namespace std;

int N, K, mod, n, a, b;

int main() {
  cin >> N >> K;
  mod = N % K;
  n = (N - mod) / K;
  a = abs(N - n * K);
  b = abs(N - (n + 1) * K);
  if (a < b) {
    cout << a;
  } else {
    cout << b;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long minimum = n % k;
  while (n % k > k - n % k) {
    minimum = k - n % k;
    n = k - n % k;
  }
  cout << minimum;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int minimum = k % n;
  while (k % n > k - k % n) {
    minimum = k - k % n;
    n = k - k % n;
  }
  cout << minimum;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main(void) {
  long int N, K;
  cin >> N >> K;

  long int remain1 = N % K;
  long int remain2 = abs(remain1 - K);

  if (remain1 < remain2) {
    cout << remain1;
  } else {
    cout << remain2;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main(void) {
  // input
  long int N, K;
  cin >> N >> K;

  long int pre_N = N;
  long int limit = pow(10, 18);
  rep(i, limit) {
    N = abs(N - K);
    if (pre_N < N)
      break;
    pre_N = N;
    // cout << i;
  }
  // answer
  cout << pre_N;

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  long long N, K;
  cin >> N >> K;
  if (N > K) {
    N = N - (N / K) * K;
  }
  cout << min(N, K - N);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  long long N, K;
  cin >> N >> K;
  while (N > K) {
    N -= K;
  }
  cout << min(N, K - N);
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  long N, K;
  cin >> N >> K;

  long p_rest, n_rest;
  p_rest = N % K;
  n_rest = p_rest - K;

  if (p_rest <= -n_rest) {
    cout << p_rest << endl;
  } else {
    cout << -n_rest << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;

  int p_rest, n_rest;
  p_rest = N % K;
  n_rest = p_rest - K;

  if (p_rest <= -n_rest) {
    cout << p_rest << endl;
  } else {
    cout << -n_rest << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

/*Bismillahir Rahmanir Rahim*/

#include <bits/stdc++.h>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#define ll long long int
#define dd double
using namespace std;

int main() {
  long long a, b, x, y;
  cin >> a >> b;
  x = a % b;
  y = abs(x - b);
  if (x < y)
    cout << x << endl;
  else {
    cout << y << endl;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, M, m;
  cin >> a >> b;
  M = max(a, b);
  m = min(a, b);
  if (b == 1)
    cout << 0;
  else
    cout << abs(m - M % m);
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  ll remainder = n % k;
  ll output = min(remainder, abs(k - remainder));
  cout << output << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  ll output = n % abs(n - k);
  cout << output << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  cout << min(n % k, k - n % k) << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  cout << n % k << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define vi(v) vector<int> v;
#define all(v) v.begin(), v.end()

using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;

  cout << min(k - (n % k), n % k) << '\\n';
  // else if(n%k!=0&&n<k)
  //    cout<<min(n%k, n);
  // else
  //    cout<<"0";

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define vi(v) vector<int> v;
#define all(v) v.begin(), v.end()

using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  while (true) {
    if (n % k == 0) {
      cout << "0";
      break;
    }
    if (n <= k) {
      cout << min(n, k - n);
      break;
    } else
      n = abs(n - k);
  }

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0;
    return 0;
  }
  while (n >= k) {
    n %= k;
  }
  if (abs(n - k) > n)
    cout << n;
  else
    cout << abs(n - k);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0;
    return 0;
  }
  while (n >= k) {
    int p = n / k;
    n = n - p * k;
  }
  if (abs(n - k) > n)
    cout << n;
  else
    cout << abs(n - k);
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  long long a = n % k;
  long long ans = min(a, k - a);
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int a = n % k;
  int ans = min(a, k - a);
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b;
  cin >> a >> b;
  a %= b;
  cout << min(a, b - a);
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int zuidagongyueshu(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (b, a % b);
  }
}
int main() {
  int a, b;
  cin >> a >> b;
  if (a % b == 0) {
    cout << 0;
    return 0;
  }
  cout << zuidagongyueshu(a, b);

  return 0;
}