#include #include #include "prime_gen.h" #include "arith_utils.h" int mod_sum(int x, int y, int mod){ x %= mod; y %= 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