pub fn jacobi_symbol(n: i64, d: u64) -> i8 {
	if d == 1 {
		return 1
	}

	let mut num = mod_abs(n, d);
	let mut den = d;

	let mut jacobi: i8 = 1;

	loop{
		num = num % den;

		//can this step be done only once at the beginning?
		if gcd(num, den) != 1 {
			return 0
		}

		let num_even_pow = mut_even_power(&mut num);
		jacobi *= jacobi_even_power(num_even_pow, d);

		if num == 1 {
			return jacobi
		}

		if num == d-1 {
			return jacobi * jacobi_neg(den)
		}

		if jacobi_flip(num, den) {
			jacobi *= -1;
		}

		std::mem::swap(&mut num, &mut den);
	}
}
//jacobi symbol only defined for odd d
jacobi symbol only defined for odd d
jacobi symbol only defined for odd d
pub fn jacobi_symbol(n: i64, d: u64) -> i8 {
	if d == 1 {
		return 1
	}
	let mut num = mod_abs(n, d);
	let mut den = d;
	let mut jacobi: i8 = 1;
	loop{
		num = num % den;
		//can this step be done only once at the beginning?
		if gcd(num, den) != 1 {
			return 0
		}
		let num_even_pow = mut_even_power(&mut num);
		jacobi *= jacobi_even_power(num_even_pow, d);
		if num == 1 {
			return jacobi
		}
		if num == d-1 {
			return jacobi * jacobi_neg(den)
		}
		if jacobi_flip(num, den) {
			jacobi *= -1;
		}
		std::mem::swap(&mut num, &mut den);
	}
}
pub fn jacobi_symbol ( n : i64 , d : u64 ) -> i8 { if d == 1 { return 1 } let mut num = mod_abs ( n , d ) ; let mut den = d ; let mut jacobi : i8 = 1 ; loop { num = num % den ; //can this step be done only once at the beginning? if gcd ( num , den ) != 1 { return 0 } let num_even_pow = mut_even_power ( & mut num ) ; jacobi *= jacobi_even_power ( num_even_pow , d ) ; if num == 1 { return jacobi } if num == d - 1 { return jacobi * jacobi_neg ( den ) } if jacobi_flip ( num , den ) { jacobi *= - 1 ; } std :: mem :: swap ( & mut num , & mut den ) ; } }
jacobi symbol only defined for odd d
jacobi symbol only defined for odd d
n
i64
d
u64