Skip to content

Commit 77f4ce2

Browse files
add doctest for primitive root
1 parent 94cc5aa commit 77f4ce2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn mod_mul(a: i64, b: i64, p: i64) -> i64 {
2121
///
2222
/// # Returns
2323
/// The result of the exponentiation modulo `p`.
24-
fn mod_exp(mut base: i64, mut exp: i64, p: i64) -> i64 {
24+
pub fn mod_exp(mut base: i64, mut exp: i64, p: i64) -> i64 {
2525
let mut result = 1;
2626
base %= p;
2727
while exp > 0 {
@@ -251,6 +251,15 @@ fn factorize(n: i64) -> HashMap<i64, u32> {
251251
///
252252
/// # Returns
253253
/// A primitive root modulo `p^e`.
254+
///
255+
/// # Examples
256+
///
257+
/// ```
258+
/// // For p = 17 and e = 2, we compute a primitive root modulo 289.
259+
/// let p = 17;
260+
/// let e = 2;
261+
/// let g = ntt::primitive_root(p, e);
262+
/// assert_eq!(ntt::mod_exp(g, p*(p-1), p*p), 1);
254263
pub fn primitive_root(p: i64, e: u32) -> i64 {
255264
let g = primitive_root_mod_p(p);
256265
let mut g_lifted = g; // Lift it to p^e

0 commit comments

Comments
 (0)