awk -M '\

function abs(x){
    x+=0
    return x>0?x:-x
}
function floor(x){
    x+=0
    if(x%1){
        if(x>0)return int(x);
        else   return int(x)-1;
    }else      return x; 
}
function f(x){
    return floor(A*x/B) - A*floor(x/B)
}
{
    A = $1;
    B = $2;
    N = $3;
    x0 = 0;
    x1 = N;
    while(abs(x0-x1)>1){
        if(f(x0) < f(x1)){
            x0 = int((x0 + x1)/2)
        }else{
            x1 = int((x0 + x1)/2)
        }
    }
    if(f(x0) < f(x1)){
        print f(x1);
    }else{
        print f(x0);
    }
}'