Click here to Skip to main content
15,918,967 members

Comments by Member 16046597 (Top 2 by date)

Member 16046597 9-Jul-23 8:08am View    
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextInt();
long m= sc.nextInt();
long x= sc.nextInt();
long y= sc.nextInt();
int count =0;
evolve(n,m,x,y,count);
}

public static void evolve(long n,long m,long x,long y,long count)
{

if(n<=0)
{
System.out.println(count);
return;
}

long quotient = m/x;
if (quotient <= 0)
{
n--;
m=m+y;
evolve(n,m,x,y,count);
}
else
{
count=count+quotient;
n=n-quotient;
m= m-(x*quotient);
evolve(n,m,x,y,count);
}
} i tried this code but only 5 test case solved out of 9
Member 16046597 9-Jul-23 8:06am View    
post the code