Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I, N) for (i8t I = 0, I##_N = N; I < I##_N; I++)
#define FR(I, N) for (i8t I = N; I--;)
#define R(V)                                                                   \
  i8t V;                                                                       \
  std::cin >> V;
#define RV(V, N)                                                               \
  std::vector<i8t> V;                                                          \
  F(_i, N) { R(_x) V.push_back(_x); }
#define RL1(line) std::getline(std::cin, line);
#define RL(line)                                                               \
  std::string line;                                                            \
  RL1(line)
#define RM(V, L, C)                                                            \
  std::vector<char> V;                                                         \
  F(_i, L) { RL(_l) F(_j, C) V.push_back(_l[_j]); }
#define P(X) std::cout << (X) << std::endl;

i8t div_ceil(i8t a, i8t b) { return (a + b - 1) / b; }

int main() {
  R(A) R(B) R(N);
  i8t mx = 0;
  for (i8t x = 1; x <= N;) {
    mx = std::max(mx, A * x / B - A * (x / B));
    auto next_floor1_num = (A * x / B + 1) * B;
    auto next_floor2_num = (x / B + 1) * B;
    auto x1 = div_ceil(next_floor1_num, A);
    x = std::min(x1, next_floor2_num);
  }
  P(mx);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I, N) for (i8t I = 0, I##_N = N; I < I##_N; I++)
#define FR(I, N) for (i8t I = N; I--;)
#define R(V)                                                                   \
  i8t V;                                                                       \
  std::cin >> V;
#define RV(V, N)                                                               \
  std::vector<i8t> V;                                                          \
  F(_i, N) { R(_x) V.push_back(_x); }
#define RL1(line) std::getline(std::cin, line);
#define RL(line)                                                               \
  std::string line;                                                            \
  RL1(line)
#define RM(V, L, C)                                                            \
  std::vector<char> V;                                                         \
  F(_i, L) { RL(_l) F(_j, C) V.push_back(_l[_j]); }
#define P(X) std::cout << (X) << std::endl;

i8t div_ceil(i8t a, i8t b) { return (a + b - 1) / b; }

int main() {
  R(A) R(B) R(N);
  i8t mx = 0;
  if (N >= B)
    N = B;
  for (i8t x = 1; x <= N;) {
    mx = std::max(mx, A * x / B - A * (x / B));
    auto next_floor1_num = (A * x / B + 1) * B;
    auto next_floor2_num = (x / B + 1) * B;
    auto x1 = div_ceil(next_floor1_num, A);
    x = std::min(x1, next_floor2_num);
  }
  P(mx);
  return 0;
}