malachite-base 0.4.6

A collection of utilities, including new arithmetic traits and iterators that generate all values of a type
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use crate::num::basic::unsigneds::PrimitiveUnsigned;

pub fn naive_mod_pow<T: PrimitiveUnsigned>(x: T, exp: u64, m: T) -> T {
    if m == T::ONE {
        return T::ZERO;
    }
    let data = T::precompute_mod_mul_data(&m);
    let mut out = T::ONE;
    for _ in 0..exp {
        out.mod_mul_precomputed_assign(x, m, &data);
    }
    out
}