alexjercan/bugnet huggingface dataset:
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

/*我是萌新*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;
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; }
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ll a, b, n;
  while (cin >> a >> b >> n) {
    ll maxn = -mod, k = 0;
    /*for(ll i=1;i<=min(n,b);i++)
    {
        if(maxn<((a*i)/b-a*(i/b)))
        {
            maxn=((a*i)/b-a*(i/b));
            k=i;
        }

    }*/
    cout << (a * min(n, b - 1)) / b - a * (min(n, b - 1) / b) << '\\n';
  }
}

Error: TLE

Fixed submission:

/*我是萌新*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;
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; }
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ll a, b, n;
  while (cin >> a >> b >> n) {
    ll maxn = -mod, k = 0;
    for (ll i = 1; i <= min(n, b); i++) {
      if (maxn < ((a * i) / b - a * (i / b))) {
        maxn = ((a * i) / b - a * (i / b));
        k = i;
      }
    }
    cout << maxn << '\\n';
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define endl '\\n'
typedef long long LL;
using namespace std;

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

  LL a, b, n;
  cin >> a >> b >> n;
  LL x = min(b - 1, n);
  LL ans = (a * x) / b - a * (x / b);
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define endl '\\n'
typedef long long LL;
using namespace std;

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

  LL a, b, n;
  cin >> a >> b >> n;
  LL ans = 0;
  for (LL i = 1; i <= b - 1; i++) {
    LL cur = (a * i) / b - a * (i / b);
    // cout << i << ' ' << cur << endl;
    if (i <= n) {
      ans = max(cur, ans);
    }
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

// 17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define MP make_pair
#define int long long
#define ll long long
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define ld long double
#define eb emplace_back
#define pii pair<int, int>
#define ull unsigned long long
#define all(v) v.begin(), v.end()
#define f(i, x, n) for (int i = x; i < n; i++)
#define fr(i, x, n) for (int i = x; i >= n; i--)
#define fastio ios::sync_with_stdio(false)

void IO() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  // IO();
  fastio;
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll a, b, n;
  cin >> a >> b >> n;
  ll x, y;
  if (n < b) {
    x = n;
    y = (a * x) / b - a * (x / b);
    cout << y << endl;
  } else if (n % b == 0) {
    x = b - 1;
    y = (a * x) / b - a * (x / b);
    cout << y << endl;
  } else {
    x = b - 1;
    y = (a * x) / b - a * (x / b);
    cout << y << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

// 17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define MP make_pair
#define int long long
#define ll long long
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define ld long double
#define eb emplace_back
#define pii pair<int, int>
#define ull unsigned long long
#define all(v) v.begin(), v.end()
#define f(i, x, n) for (int i = x; i < n; i++)
#define fr(i, x, n) for (int i = x; i >= n; i--)
#define fastio ios::sync_with_stdio(false)

void IO() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  // IO();
  fastio;
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll a, b, n;
  cin >> a >> b >> n;
  ll mx = -1;
  ll x = b / a;
  ll hi = b;
  ll y = 0;
  while (x <= hi && x <= n) {
    y = (a * x) / b - a * (x / b);
    mx = max(mx, y);
    x++;
  }
  cout << mx << endl;

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

#include <iostream>

using namespace std;

int main() {
  long int a, b, n;
  long int ans;
  int c, d, e;
  cin >> a >> b >> n;
  if (b > n) {
    d = a * n / b;
    e = n / b;
    c = d - a * e;
    ans = c;
  } else {
    d = a * (b - 1) / b;
    e = (b - 1) / b;
    c = d - a * e;
    ans = c;
  }

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  long int a, b, n;
  long int ans = -9999;
  int c, d, e;
  cin >> a >> b >> n;
  d = a * n / b;
  e = n / b;
  c = d - a * e;
  ans = c;
  for (int i = b - 1; i < n + 1; i += b) {
    d = a * i / b;
    e = i / b;
    c = d - a * e;
    if (c > ans) {
      ans = c;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 1LL << 20;
template <class T> inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void execute();
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false); // cin と scanfの併用禁止
  cout << fixed << setprecision(15);
  execute();
  return 0;
}

void execute() {
  ll A, B, N;
  cin >> A >> B >> N;

  ll x;
  if (N < B) {
    x = N;
  } else {
    x = B - 1;
  }
  ll v = (A * x / B) - A * (x / B);

  cout << v << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 1LL << 20;
template <class T> inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void execute();
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false); // cin と scanfの併用禁止
  cout << fixed << setprecision(15);
  execute();
  return 0;
}

void execute() {
  ll A, B, N;
  cin >> A >> B >> N;

  ll ma = 0;
  for (ll x = N; N - B <= x; x--) {
    ll v = (A * x / B) - A * (x / B);
    if (ma < v)
      ma = v;
  }

  cout << ma << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

#define MOD 1e9 + 7;
#define INF 1e17 + 9;
#define PI acos(-1);

using namespace std;

long long calc(long long a, long long b, long long x) {
  long long answer;
  answer = ((a * x) - (a * x % b)) / b - a * ((x - (x % b)) / b);
  return answer;
}

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long X = min(n, b - 1);
  cout << calc(a, b, X) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

#define MOD 1e9 + 7;
#define INF 1e17 + 9;
#define PI acos(-1);

using namespace std;

long long floor(int x, int y) { return x / y; }

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long now, mx = 0;
  for (long long i = 0; i <= n; i++) {
    now = floor(a * i, b) - a * floor(i, b);
    // cout << now << endl;
    mx = max(mx, now);
  }
  cout << mx << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long A, B, N;

  cin >> A >> B >> N;
  long long result = 0;
  long long count = 0;
  long long x = 1;
  long long tmp = 0;
  long long tmp2 = 0;

  if (A <= B && B < N) {
    long long num = B - 1;
    tmp = floor((A * num) / B) - A * floor(num / B);
    cout << tmp << endl;
    return 0;
  } else if (A <= B && B > N) {
    tmp = floor((A * N) / B) - A * floor(N / B);
    cout << tmp << endl;
    return 0;
  } else if (A <= B && B == N) {
    long long num = N - 1;
    tmp = floor((A * num) / B) - A * floor(num / B);
    cout << tmp << endl;
    return 0;
  } else if (A > B && B < N) {
    tmp = floor((A * B) / B) - A * floor(B / B);
    cout << tmp << endl;
    return 0;
  } else if (A > B && B == N) {
    long long num = N - 1;
    tmp = floor((A * num) / B) - A * floor(num / B);
    cout << tmp << endl;
    return 0;
  } else {
    tmp = floor((A * N) / B) - A * floor(N / B);
    cout << tmp << endl;
    return 0;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using namespace std;

int main() {
  long long A, B, N;

  cin >> A >> B >> N;
  long long result = 0;
  long long count = 0;
  long long x = 1;
  long long tmp = 0;
  while (1) {
    tmp = floor((A * x) / B) - A * floor(x / B);

    if (tmp >= result) {
      result = tmp;
    } else {
      break;
    }

    if (N <= x) {
      break;
    }

    x++;
  }

  cout << result << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

// author: zekigurbuz (Zeki Gurbuz) 2020
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

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

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define all(x) begin(x), end(x)

const int N = 1e5 + 10;
const int M = 1e9 + 7;

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

template <class T> void ckmin(T &a, T b) { a = min(a, b); }
template <class T> void ckmax(T &a, T b) { a = max(a, b); }

void precomp() {}

ll a, b, n;

ll f(ll x) { return (a * x) / b - a * (x / b); }

void solve() {
  cin >> a >> b >> n;
  cout << f(min(b - 1, n));
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  precomp();
  int t = 1; // cin >> t;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

// author: zekigurbuz (Zeki Gurbuz) 2020
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

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

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define all(x) begin(x), end(x)

const int N = 1e5 + 10;
const int M = 1e9 + 7;

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

template <class T> void ckmin(T &a, T b) { a = min(a, b); }
template <class T> void ckmax(T &a, T b) { a = max(a, b); }

void precomp() {}

ll a, b, n;

ll f(ll x) { return (a * x) / b - a * (x / b); }

void solve() {
  cin >> a >> b >> n;
  ll lo = 1L, hi = n;
  while (hi - lo > 1L) {
    ll left = lo + (hi - lo) / 3L, right = hi - (hi - lo) / 3L;
    if (f(left) < f(right))
      lo = left + 1;
    else
      hi = right;
  }
  ll cr = (lo + hi) / 2L;
  while (f(cr + 1L) > f(cr) && cr + 1L <= n)
    ++cr;
  while (f(cr - 1L) > f(cr) && cr - 1L >= 1L)
    --cr;
  cout << f(cr) << endl;
  // for (ll i = 1L; i <= n; i++) cout << i << " " << f(i) << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  precomp();
  int t = 1; // cin >> t;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
int main() {
  ll a, b, n, x, t;
  ll ans;
  cin >> a >> b >> n;
  if (n < b)
    ans = a * n / b;
  else if (b == 1)
    ans = 0;
  else {
    x = b - 1;
    t = n / b;
    x += (t - 1) * b;
    ans = a * x / b - a * (x / b);
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
int main() {
  ll a, b, n;
  ll max_num = 0;
  ll ans;
  cin >> a >> b >> n;
  for (ll i = 1; i <= n; i++) {
    ans = a * i / b - a * (i / b);
    if (ans > max_num)
      max_num = ans;
  }
  cout << max_num;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template <class T> void print(const T &t) { cout << t << endl; }
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (n < b) {
    ans = a * n / b - n / b * a;
  } else {
    ans = a * (b - 1) / b;
  }
  print(ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template <class T> void print(const T &t) { cout << t << endl; }
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll num = 0;
  for (ll i = n; i >= 1; i--) {
    if (ans > a * i / b) {
      break;
    }
    num = a * i / b - i / b * a;
    chmax(ans, num);
  }
  print(ans);
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <stdio.h>

#define LL long long

int main() {

  LL a, b, n, r;

  scanf("%lld%lld%lld", &a, &b, &n);

  if (n < b)
    r = n;

  else
    r = b - 1;

  printf("%lld\\n", r * a / b);

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long arr[7] = {0};
  long long sum, max = -123, i;
  long long a, b, n;
  scanf("%lld%lld%lld", &a, &b, &n);
  arr[0] = floor(n * a / b) - a * floor(n / b);
  arr[1] = floor((n - 1) * a / b) - a * floor((n - 1) / b);
  for (i = n - 2; i >= n / b && i >= a; i--) {
    sum = floor(i * a / b) - a * floor(i / b);
    if (sum > max)
      max = sum;
  }
  sort(arr, arr + 2);
  if (arr[1] > max)
    printf("%lld", arr[1]);
  else
    printf("%lld", max);
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e6 + 5;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, n;
  cin >> a >> b >> n;
  n = min(n, b - 1);
  cout << a * n / b << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll a, b, n, ans = -1, t = 0;
  cin >> a >> b >> n;
  for (int x = 0; x <= n; x++) {
    t = floor(a * x / b) - a * floor(x / b);
    if (t > ans)
      ans = t;
  }
  cout << ans;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll a, b, n;

ll floor(ll N) {
  ll fl1 = (a * N) / b;
  ll fl2 = N / b;
  ll ans = fl1 - a * fl2;
  return ans;
}

int main() {
  cin >> a >> b >> n;
  ll ans = floor(min(b - 1, n));
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  int curMax = 0;
  for (int i = 1; i <= n; i++) {
    ll floor1 = (a * i) / b;
    ll floor2 = i / b;
    ll ans = floor1 - a * floor2;
    if (curMax <= ans)
      curMax = ans;
  }
  cout << curMax << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

typedef long long LL;

int main() {
  ios::sync_with_stdio(false);
  LL a, b, n, x;

  cin >> a >> b >> n;

  x = (n < b) ? n : (b - 1);

  cout << a * x / b - a * (x / b);

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

typedef long long LL;

int main() {
  ios::sync_with_stdio(false);
  LL a, b, n, Max = 0, temp;

  cin >> a >> b >> n;

  for (LL x = 1; x <= n; x++) {
    temp = a * x / b - a * (x / b);
    if (temp > Max)
      Max = temp;
  }
  cout << Max;

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

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

void solve() {
  long long a, b, n;
  cin >> a >> b >> n;
  if (n < b)
    cout << (a * n / b);
  else
    cout << (a * (b - 1) / b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}


Error: TLE

Fixed submission:

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

void solve() {
  long long a, b, n, res;
  cin >> a >> b >> n;
  long long mx = 0;
  for (long long i = 1; i <= n; i++) {
    res = (a * i / b);
    res -= (a * (i / b));
    mx = max(mx, res);
  }
  cout << mx;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (long long i = 0; i < (n); i++)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll res = 0;
  if (b - 1 <= n)
    chmax(res, a * (b - 1) / b);
  chmax(res, a * n / b - a * (n / b));
  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (long long i = 0; i < (n); i++)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll res = 0;
  if (b - 1 <= n)
    chmax(res, a * (b - 1) / b);
  for (ll i = n; (i > 0 && i % b != b - 1); i--) {
    chmax(res, (a * i) / b - a * (i / b));
  }
  cout << res << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void solve(long long A, long long B, long long N) {
  long long x = N < B ? N : B - 1;
  long long ans = floor((A * (x % B)) / B);
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long N;
  scanf("%lld", &N);
  solve(A, B, N);
  return 0;
}


Error: TLE

Fixed submission:

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

void solve(long long A, long long B, long long N) {
  long long ans = 0;
  for (long long i = 1; i <= B - 1 && i <= N; i++) {
    ans = max(ans, (A * (i % B) - (A * i) % B) / B);
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long N;
  scanf("%lld", &N);
  solve(A, B, N);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  if (b - 1 > n) {
    cout << (a * n) / b - a * (n / b) << endl;
    return 0;
  }
  long long s = 1;
  long long x1 = b - 1;
  long long x2 = b * (n / b) - 1;
  long long ans1 = (a * x1) / b - a * (x1 / b);
  long long ans2 = (a * x2) / b - a * (x2 / b);
  cout << max(ans1, ans2) << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  if (b - 1 > n) {
    cout << (a * n) / b - a * (n / b) << endl;
    return 0;
  }
  long long ans = 0;
  long long s = 1;
  while (true) {
    long long x = s * b - 1;
    if (x > n) {
      break;
    }
    long long tmp = (a * x) / b - a * (x / b);
    ans = max(tmp, ans);
    ++s;
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long int A, B, N;
  cin >> A >> B >> N;
  long long MEM = 0;
  long long ANS = 0;
  long long x;
  long long x_2;
  if (N < B - 1) {
    x = N;
  } else {
    int NB = N / B;
    x = B * NB - 1;
    if (x + B <= N) {
      x += B;
    }
  }
  ANS = floor(A * x / B) - A * floor(x / B);
  cout << ANS << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  long int A, B, N;
  cin >> A >> B >> N;
  long long MEM = 0;
  long long ANS = 0;
  long long x;
  long long x_2;
  if (N < B - 1) {
    x = N;
  } else {
    x = B - 1;
    while (x <= N) {
      x += B;
    }
    x -= B;
  }
  ANS = floor(A * x / B) - A * floor(x / B);
  cout << ANS << endl;
}