Problem:
Score : 400 points

Problem Statement

Given are integers A, B, and N.

Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.

Here floor(t) denotes the greatest integer not greater than the real number t.

Constraints

1 ≤ A ≤ 10^{6}

1 ≤ B ≤ 10^{12}

1 ≤ N ≤ 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B N

Output

Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.

Sample Input 1

5 7 4

Sample Output 1

2

When x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.

Sample Input 2

11 10 9

Sample Output 2

9

Solution in C++ (GCC 9.2.1) (judge verdict: Runtime Error)

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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=100,mod=1e9+7,bit=61;
const ld PI=acos(-1.00);

ll a,b,n;

ll fun(ll x)
{
    assert(x>=0 and x<=n);
    ll ans=((a*x)/b)-a*(x/b);
    return ans;
}

signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        scanf("%lld %lld %lld",&a,&b,&n);
        ll mx=(a*n)/b;
        ll l=0,r=n,x=n;
        while(l<=r)
        {
            ll mid=(l+r)>>1;
            ll nw=(a*mid)/b;
            if(nw==mx)
            {
                x=min(x,mid);
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        ll ans=fun(x);
        f(i,0,min(5000000ll,n))
        {
            ans=max(ans,fun(i));
            ans=max(ans,fun(n/max(1ll,i)));
        }
        f(i,1,5000000)
        {
            ll x=i;
            ll k=min(b*x+b-1,n);
            ans=max(ans,fun(k));
            x=b/i;
            k=min(b*x+b-1,n);
            ans=max(ans,fun(k));
        }
        ans=max(ans,fun(min(n,b-1)));
        ans=max(ans,fun(min(n,a)));
        ans=max(ans,fun(n));
        //assert(ans<=fun(min(a,b-1)));
        printf("%lld\n",ans);
    }
    return 0;
}