# Distinct Degree Factorization # This version works whether or not ff is squarefree # It could be made more efficient... DDFact:=proc(ff,x,p) local f,h,g,G,i,n,gg; f:=ff; n:=degree(f,x); h:=x; G:=NULL; for i from 1 to n while f<>1 do h:=Powmod(h,p,f,x) mod p; g:=Gcd(h-x,f) mod p; gg:=Gcd(f,g^ceil(n/i)) mod p; f:=Quo(f,gg,x) mod p; G:=G,g; od; G; end: