$3{for(y=$1;($1<x=y*$2/$3)+--x%1;y--);print x,y}
5 1 1 1 5 2 5 5 3 2 5 0 1 50 48 49
0 1 1 5 2 2 -1 5 47 49
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!