while 1: i=0;j=1 for l in iter(raw_input,''): \x09exec l.replace('(mod','-i;b=y=(');a=j;t=w=0;u=v=1 \x09while a:a,b,t,u,v,w=b%a,a,v,w,t-b/a*v,u-b/a*w \x09j*=x%b<1<y>x;y/=b;i+=x/b*t%y*j;j*=y print('no solutions','%d + %dk'%(i,j))[j>0]
Note that non-ascii characters in the above source code will be escaped (such as \x9f).