#include #include #include "prime_gen.h" #include "arith_utils.h" //Expects 0 <= x,y < mod int mod_sum(int x, int y, int mod){ if(y >= mod - x){ return y - (mod - x); } else{ return y + x; } } int mod_inv(int n, int mod){ int y, a; if(n!=0){ while(n<0){ n+=mod; } for(y = 1; y < mod; y++){ a = mod_product(y, n, mod); if(a == 1){ return y; } } } return 0; } int coprime(int n1, int n2){ //naive algorithm but efficient when n1 has already been factorized int * n1Factors = prime_factors(n1); int numOfFactors = *n1Factors; int * factors = n1Factors+1; int shareFactor = 0; int i; for(i=0; i= 0; i--){ tot = mod_product(tot, x, mod); tot = mod_sum(tot, coeffs[i], mod); } return tot; } long eval_polynomial(int degree, int coeffs[], int x){ long int sum = coeffs[0]; long int powx; int i; for(i = 1, powx = x; i <= degree; i++, powx*=x){ sum += powx*coeffs[i]; } return sum; } /* int * linear_diophantine_solution(int order, int coeffs[], int scal){ *=} */