Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

// containing t test cases
#include <bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define mkp make_pair
#define fi first
#define se second
#define ll long long
#define scan(n)                                                                \\
  ll a[n];                                                                     \\
  for (ll i = 0; i < n; i++)                                                   \\
  cin >> a[i]
#define print(a, n)                                                            \\
  for (int i = 0; i < n; i++)                                                  \\
  cout << a[i] << ' '
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define rep(i, x, y) for (ll i = x; i < y; i++)
// #define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
/*vi adj[200005];
ll vis[200005];
ll parent[200005];
ll level[200005];
ll arr[200005];
ll size[200005];*/
// endl mut bhool!!
int main() {
  fast;
  int test = 1;
  // cin>>test;
  while (test--) {
    ll a, b, n, x;
    cin >> a >> b >> n;
    ll flag = 0;
    ll y = n % b;
    x = n - y - 1;
    if (x <= 0) {
      x = n;
    }
    cout << floor((a * x) / b) - a * floor(x / b);
  }
  return 0;
}
/*
cout<<"YES"<<endl;
cout<<"NO"<<endl;
*/


Error: TLE

Fixed submission:

// containing t test cases
#include <bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define mkp make_pair
#define fi first
#define se second
#define ll long long
#define scan(n)                                                                \\
  ll a[n];                                                                     \\
  for (ll i = 0; i < n; i++)                                                   \\
  cin >> a[i]
#define print(a, n)                                                            \\
  for (int i = 0; i < n; i++)                                                  \\
  cout << a[i] << ' '
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define rep(i, x, y) for (ll i = x; i < y; i++)
// #define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
/*vi adj[200005];
ll vis[200005];
ll parent[200005];
ll level[200005];
ll arr[200005];
ll size[200005];*/
// endl mut bhool!!
int main() {
  fast;
  int test = 1;
  // cin>>test;
  while (test--) {
    ll a, b, n, x;
    cin >> a >> b >> n;
    ll flag = 0;
    for (ll i = n; i > 0; i--) {
      if (i % b == 0) {
        x = i - 1;
        flag = 1;
        break;
      }
    }
    if (!flag) {
      x = n;
    }
    cout << floor((a * x) / b) - a * floor(x / b);
  }
  return 0;
}
/*
cout<<"YES"<<endl;
cout<<"NO"<<endl;
*/