Cod sursa(job #731747)

Utilizator soriynSorin Rita soriyn Data 9 aprilie 2012 00:42:24
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<fstream>
#include<cstdlib>

using namespace std;
long long d,b,t,p,s,x,sol=1<<54;

long long ok;

ifstream in("video.in");
ofstream out("video.out");

void cauta(long long start,long long end)
{
	
	     
	         while(start!=end)
			 {
				if(start==end-1 && (t*(b-d)/start!=x && t*(b-d)%start==0) || ( t*(b-d)/start+1LL!=x && t*(b-d)%start!=0 ) )
					if((t*(b-d)/end==x && t*(b-d)%end==0) || ( t*(b-d)/end+1LL==x && t*(b-d)%end!=0 ) && sol>end ){out<<end;exit(0);}
				int mij=(start+end)/2; 
			   if( (t*(b-d)/mij==x && t*(b-d)%mij==0) || ( t*(b-d)/mij+1LL==x && t*(b-d)%mij!=0 ) )
				   sol=mij,cauta(start,mij);
			   else cauta(mij,end);
			 }
		out<<sol;
        exit(0);		
		 
}

int main()
{
	in>>d>>b>>t>>p;
	s=p*d;
	if(t*(b-d)%s!=0) x=t*(b-d)/s+1;
	else x=t*(b-d)/s,ok=1;
	cauta(1,p*d);
}