int fmpz_moebius_mu(const fmpz_t n) { fmpz_factor_t factors; long i; int mu; if (fmpz_abs_fits_ui(n)) return n_moebius_mu(fmpz_get_ui(n)); fmpz_factor_init(factors); fmpz_factor(factors, n); mu = 1; for (i = 0; i < factors->num; i++) { if (fmpz_get_ui(factors->exp + i) != 1UL) { mu = 0; break; } } if (factors->num % 2) mu = -mu; fmpz_factor_clear(factors); return mu; }
void fmpz_ramanujan_tau(fmpz_t res, const fmpz_t n) { fmpz_factor_t factors; if (fmpz_sgn(n) <= 0) { fmpz_zero(res); return; } fmpz_factor_init(factors); fmpz_factor(factors, n); _fmpz_ramanujan_tau(res, factors); fmpz_factor_clear(factors); }
void arith_euler_phi(fmpz_t res, const fmpz_t n) { fmpz_factor_t factors; fmpz_t t; ulong exp; slong i; if (fmpz_sgn(n) <= 0) { fmpz_zero(res); return; } if (fmpz_abs_fits_ui(n)) { fmpz_set_ui(res, n_euler_phi(fmpz_get_ui(n))); return; } fmpz_factor_init(factors); fmpz_factor(factors, n); fmpz_one(res); fmpz_init(t); for (i = 0; i < factors->num; i++) { fmpz_sub_ui(t, factors->p + i, UWORD(1)); fmpz_mul(res, res, t); exp = factors->exp[i]; if (exp != 1) { fmpz_pow_ui(t, factors->p + i, exp - UWORD(1)); fmpz_mul(res, res, t); } } fmpz_clear(t); fmpz_factor_clear(factors); }