Esempio n. 1
0
/**
\brief 有限域Fp上多项式在Fp中的根(不含重数)
\param f Fp[x]中多项式
\param p 阶数
\return 根的集合
\note 利用因子分解算法求解
*/
void UniZpRootZp(std::vector<mpz_ptr> & rootlist,const poly_z & f,mpz_ptr p)
{
    resize_z_list(rootlist,0);
    poly_z h0,h;
    h0.resize(2);
    mpz_set_ui(h0[0],0);
    mpz_set_ui(h0[1],1);
    copy_poly_z(h,h0);

    PowerMod(h,p,f,p);

    mpz_sub_ui(h[1],h[1],1);
    UniGcdZp(h0,h,f,p);
    if(h0.size()==1)
    {
        h0.resize(0);
        h.resize(0);
        return ;
    }
    std::vector<poly_z> faclist;
    UniEqlDegFacZp(faclist,h0,p,1);
    for(uint i=0; i<faclist.size(); i++)
    {
        resize_z_list(rootlist,i+1);
        mpz_neg(rootlist[i],faclist[i][0]);
    }
    clear_poly_z_list(faclist);
    h0.resize(0);
    h.resize(0);
    std::sort(rootlist.begin(),rootlist.end(),mpz_ptr_less);
    return ;
}
Esempio n. 2
0
void UniEqlDegFacZp(std::vector<poly_z> & eqlfactorlist,const poly_z & f,mpz_ptr p,uint d,uint & current)
{
	uint n=f.size()-1;
	if(n==d)
	{
		copy_poly_z(eqlfactorlist[current],f);
		current++;
		return ;
	}
	poly_z g,h;
	while(1)
	{
		UniEqlDegFacZp_Odd(g,f,p,d);
		if(g.size()>=d)break;
	}
	UniEqlDegFacZp(eqlfactorlist,g,p,d,current);
	UniDivZp(h,f,g,p);
	UniEqlDegFacZp(eqlfactorlist,h,p,d,current);
	g.resize(0);h.resize(0);
	return ;
}