fork download
  1. s=$3{for(y=$1;(x=y*$2+1)%s||$1<x/=s;y--);print x,y}
Success #stdin #stdout 0s 5320KB
stdin
3
1 1 1
5 3 2
50 48 49
5 2 5
6 0 1
stdout
1 0
5 3
49 50
1 2
1 6