a,b=1,p,q;f(c,d){!c?b*=q/d:f(d%c,c);}main(u,s){for(;gets(s);)for(!~sscanf(s,"x =%d%*s%d",&p,&q)?p=a=!printf(b?"%d + %dk\n":"no solutions\n",a,b),b=1:f(u=b,q);a>b?b=0:a%q-p;)a+=u;}

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