Linear Congruences by nn

a=[n=0]
System.in.eachLine{if(it)a[n++]=it.split(/\D+/)[1,2]*.toLong()
else{int m=a[i=j=0][1]
for(d=a[n-1];++i<n;m=m*b/m.toBigInteger().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