Complete the code to compute the remainder of 17 divided by 5 using modular arithmetic.
let result = 17 [1] 5; println!("{}", result);
/ instead of modulo %.The % operator gives the remainder after division, which is the core of modular arithmetic.
Complete the code to compute (7 + 12) modulo 10.
let sum = (7 + 12) [1] 10; println!("{}", sum);
/ instead of modulo %.The modulo operator % calculates the remainder after division, so (7 + 12) % 10 equals 9.
Fix the error in the code to correctly compute (8 * 9) modulo 7.
let product = (8 [1] 9) % 7; println!("{}", product);
The multiplication operator * is needed to multiply 8 and 9 before taking modulo 7.
Fill both blanks to create a function that returns (a + b) modulo m.
fn mod_add(a: i32, b: i32, m: i32) -> i32 {
(a [1] b) [2] m
}We add a and b using +, then take modulo m using %.
Fill all three blanks to create a function that returns (a * b + c) modulo m.
fn mod_expr(a: i32, b: i32, c: i32, m: i32) -> i32 {
(a [1] b [2] c) [3] m
}Multiply a and b with *, add c with +, then take modulo m with %.
