s a@(c,n)=if q>0then a else s(c+1,p)where(p,q)=n`divMod`2 m n=let{(k,q)=s(0,n-1);t=map(\a->2^(q*2^a)`mod`n)[0..k];d=(`break`t)}in head t==1||d(==n-1)