i have to do division without divison/multiplication/mod operator. how can i ?
int divide(int dividend, int divisor) {
int p=1;
if(dividend<0)
{
p*=-1;
dividend*=-1;
}
if(divisor<0)
{p*=-1;
divisor*=-1;
}
while(dividend>=divisor)
{
dividend-=divisor;
}
return dividend*p;
}
i have done this, but this giving time limit exceeded when input is 1234567890,1. how can i do it efficiently ?