Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(), (x).end()
#define f(i, a, b) for (int i = a; i < (signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back
#define mp make_pair

// debug templates
#define debug(x) cerr << #x << " : " << x << endl;
#define debuga(A, N)                                                           \
  cerr << #A << " : [";                                                        \
  for (int i = 0; i < N; i++)                                                  \
    cerr << A[i] << " ";                                                       \
  cerr << "]\n";
#define debuga2(A, N, M)                                                       \
  cerr << #A << " : \n";                                                       \
  for (int i = 0; i < N; i++) {                                                \
    cerr << "[";                                                               \
    for (int j = 0; j < M; ++j)                                                \
      cerr << A[i][j] << " ";                                                  \
    cerr << "]\n";                                                             \
  }
#define debugp(p)                                                              \
  cerr << #p << " : "                                                          \
       << "(" << (p).first << "," << (p).second << ")\n";
#define debugv(v)                                                              \
  cerr << #v << " : "                                                          \
       << "[";                                                                 \
  for (int i = 0; i < (v).size(); i++)                                         \
    cerr << v[i] << " ";                                                       \
  cerr << "]\n";
#define debugv2(v)                                                             \
  cerr << #v << " : \n";                                                       \
  for (int i = 0; i < v.size(); i++) {                                         \
    cerr << "[";                                                               \
    for (int j = 0; j < (v[0].size()); ++j)                                    \
      cerr << v[i][j] << " ";                                                  \
    cerr << "]\n";                                                             \
  }
#define debugs(m)                                                              \
  cerr << #m << " : [ ";                                                       \
  for (auto itr = m.begin(); itr != m.end(); itr++)                            \
    cerr << *itr << " ";                                                       \
  cerr << "]\n";
#define debugm(m)                                                              \
  cerr << #m << " : [ ";                                                       \
  for (auto itr = m.begin(); itr != m.end(); itr++)                            \
    cerr << "(" << itr->first << "," << itr->second << ") ";                   \
  cerr << "]\n";

void solve() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = -1;

  if (n < b) {
    x = n;
  } else {
    for (ll i = n; i >= n - b; --i) {
      if (i % b == b - 1) {
        x = i;
        break;
      }
    }
  }
  cout << (a * x) / b - a * (x / b);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  solve();
}


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

#define ll long long
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(), (x).end()
#define f(i, a, b) for (int i = a; i < (signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back
#define mp make_pair

// debug templates
#define debug(x) cerr << #x << " : " << x << endl;
#define debuga(A, N)                                                           \
  cerr << #A << " : [";                                                        \
  for (int i = 0; i < N; i++)                                                  \
    cerr << A[i] << " ";                                                       \
  cerr << "]\n";
#define debuga2(A, N, M)                                                       \
  cerr << #A << " : \n";                                                       \
  for (int i = 0; i < N; i++) {                                                \
    cerr << "[";                                                               \
    for (int j = 0; j < M; ++j)                                                \
      cerr << A[i][j] << " ";                                                  \
    cerr << "]\n";                                                             \
  }
#define debugp(p)                                                              \
  cerr << #p << " : "                                                          \
       << "(" << (p).first << "," << (p).second << ")\n";
#define debugv(v)                                                              \
  cerr << #v << " : "                                                          \
       << "[";                                                                 \
  for (int i = 0; i < (v).size(); i++)                                         \
    cerr << v[i] << " ";                                                       \
  cerr << "]\n";
#define debugv2(v)                                                             \
  cerr << #v << " : \n";                                                       \
  for (int i = 0; i < v.size(); i++) {                                         \
    cerr << "[";                                                               \
    for (int j = 0; j < (v[0].size()); ++j)                                    \
      cerr << v[i][j] << " ";                                                  \
    cerr << "]\n";                                                             \
  }
#define debugs(m)                                                              \
  cerr << #m << " : [ ";                                                       \
  for (auto itr = m.begin(); itr != m.end(); itr++)                            \
    cerr << *itr << " ";                                                       \
  cerr << "]\n";
#define debugm(m)                                                              \
  cerr << #m << " : [ ";                                                       \
  for (auto itr = m.begin(); itr != m.end(); itr++)                            \
    cerr << "(" << itr->first << "," << itr->second << ") ";                   \
  cerr << "]\n";

void solve() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = -1;

  if (n < b) {
    x = n;
  } else {
    ll off = n % b;
    x = n - off - 1;
  }
  cout << (a * x) / b - a * (x / b);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  solve();
}