I have tried many times but everytime i got wrong answer my program is
working for all of the test cases given in the forum , can anybody tell me
where am i going wrong .
My logic is if V is divisible by 2*V0 then print the number V/(2*V0)
else find n = V/(2*V0) and then u will have to check for 2 values floor(n)
and floor(n)+1 and if the Max length is coming out to be same then print
0 otherwise print round(n).
here is the Code
Code: Select all
#include<stdio.h>
#include<iostream>
#include<math.h>
int main(void)
{
int V,V0;
double n,n1,L1,L2,x,z;
while(1)
{
scanf("%d%d",&V,&V0);
L1=0;L2=0;
if(V==0 && V0==0) break;
if((V%(2*V0))==0) printf("%d\n",V/(2*V0));
else
{
n = (double)V/(2*(double)V0);
n1 = n;
n = floor(n);
z = (double)V/(double)n ;
x = (double)V/(double)(n+1);
if(n!=0 && z>V0)
{
L1 = (n)*(0.3)*sqrt(z-(double)V0);
}
if(x>V0)
L2 = (n+1)*(0.3)*sqrt(x-V0);
if(L1==L2 || V==V0)printf("0\n");
else printf("%.lf\n",n1);
}
}
}