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