Linear Congruences by murky-satyr

a=[n=0]
System.in.eachLine{it?a[n++]=(it=~/\d+/)*.toLong():{int m=a[i=j=0][1]
for(d=a[n-1];++i<n;m=m*b/(0g+m).gcd(b))b=a[i][1]
for(i=d[0]-d[1];j<n&&(i+=d[1])<m;)for(j=0;j<n&&i%a[j][1]==a[j][0];)j++
println i<m?"$i + ${m}k":'no solutions'
a=[n=0]}()}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page