模平方和

x2+y2=px^2+y^2=p

  • STEP1: 求m0m_0

    寻找x=x0x=x_0,使得x21(modp)x^2\equiv-1\left(\mod p\right),存在y0=1y_0=1使得x02+y02=m0px_0^2+y_0^2=m_0\cdot p

  • STEP2:求ui,viu_i, v_i

    uixi(modmi)u_i\equiv x_i\left(\mod m_i\right)

    viyi(modmi)v_i\equiv y_i\left(\mod m_i\right)

  • STEP3: 求xi,yix_i, y_i

    xi+1=uixi+viyimix_{i+1}=\frac{u_i\cdot x_i+v_i\cdot y_i}{m_i}

    yi+1=uiyiviximiy_{i+1}=\frac{u_i\cdot y_i-v_i\cdot x_i}{m_i}

  • STEP4: 求mim_i

    xi2+yi2=mipx_i^2+y_i^2=m_i\cdot p

    mk=1m_k=1时,xk,ykx_k,y_k即为方程的解

最后更新于