Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

#define ID(x, y) (((x)-1) * m + (y))
#define CL clear
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define low_bit(x) ((x) & (-(x)))
#define dmp(x) cerr << #x << "=" << x << "\\n"
#define MIN(a, b, c) min(a, min(b, c))
#define MAX(a, b, c) max(a, max(b, c))
#define SZ(x) ((int)(x.size()))
#define sc scanf
#define pf printf
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define dep(i, a, b) for (int i = (a); i >= (b); i--)

#define int long long

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

const int N = (int)1e6 + 10;
const int mod = 1e9 + 7;
const int inf = 1e9;
const double eps = 1e-16;
const double pi = acos(-1);

inline int rd() {
  int p = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f *= -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    p = p * 10 + ch - '0';
    ch = getchar();
  }
  return p * f;
}

int A, B, n;

signed main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  int A = rd();
  int B = rd();
  int n = rd();
  int x = (n + 1) / B;
  x = x * B - 1;
  printf("%lld\\n", max((A * x / B) - A * (x / B), (A * n / B) - A * (n / B)));
  return 0;
}

/*
 */


Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

#define ID(x, y) (((x)-1) * m + (y))
#define CL clear
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define low_bit(x) ((x) & (-(x)))
#define dmp(x) cerr << #x << "=" << x << "\\n"
#define MIN(a, b, c) min(a, min(b, c))
#define MAX(a, b, c) max(a, max(b, c))
#define SZ(x) ((int)(x.size()))
#define sc scanf
#define pf printf
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define dep(i, a, b) for (int i = (a); i >= (b); i--)

#define int long long

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

const int N = (int)1e6 + 10;
const int mod = 1e9 + 7;
const int inf = 1e9;
const double eps = 1e-16;
const double pi = acos(-1);

inline int rd() {
  int p = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f *= -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    p = p * 10 + ch - '0';
    ch = getchar();
  }
  return p * f;
}

int A, B, n;

signed main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  int A = rd();
  int B = rd();
  int n = rd();
  int nx = 0;
  int ans = 0;
  for (int i = 1; i <= n; i = nx + 1) {
    nx = min(n, B / (B / i));
    // printf("%lld\\n",nx);
    ans = max(ans, A * nx / B - A * (nx / B));
  }
  return printf("%lld\\n", ans), 0;
}

/*
 */