Getting RTE on 773A

Revision en1, by prac16, 2017-06-02 01:04:21

why am i getting RTE for the below code? can someone explain

include

include <bits/stdc++.h>

using namespace std;

define ll long long

ll x,y,p,q; ll f(ll a) {

ll num=(a*p-x);
ll denum=(a*q-y);
if(denum<0||num<0)
{
    return 0;
}
if(denum>=num)
{
    return 1;
}
else
{
    return 0;
}

} int main() { //cout << "Hello world!" << endl; ll i,j ,k,t; cin>>t; while(t--) { cin>>x>>y>>p>>q;

if((double)x/y==(double)p/q)
    {
        cout<<"0\n";
        continue;
    }
    if(p>=q&&x!=y)
    {
        cout<<"-1\n";
        continue;
    }
    ll lo=(x/p),hi=10e9;
ll mid;
ll last=-1;
while(lo<hi)
{

    mid=lo+(hi-lo)/2;

    if(f(mid))
    {
        last=mid;
        hi=mid;
    }
    else
    {
        lo=mid+1;
    }
}
ll  ans=(q*last-y);
cout<<ans<<"\n";
}

return 0;

}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English prac16 2017-06-02 01:07:11 1027
en1 English prac16 2017-06-02 01:04:21 1104 Initial revision (published)