Skip to content

Commit

Permalink
Cover more codes
Browse files Browse the repository at this point in the history
  • Loading branch information
EFanZh committed Jun 6, 2024
1 parent b2a432b commit d249dae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ impl Solution {
(lhs * rhs) % Self::MODULUS
}

fn exp(mut base: u64, mut exp: u64) -> u64 {
/// Calculates base ^ ((2 ^ x) - 1)
fn exp(mut base: u64, x: u32) -> u64 {
let mut result = 1;

while exp != 0 {
if exp & 1 != 0 {
result = Self::mul(result, base);
}

for _ in 0..x {
result = Self::mul(result, base);
base = Self::mul(base, base);
exp >>= 1;
}

result
Expand All @@ -28,7 +25,7 @@ impl Solution {
let p = p as u32;
let max = (1 << p) - 1;

Self::mul(max % Self::MODULUS, Self::exp((max - 1) % Self::MODULUS, max >> 1)) as _
Self::mul(max % Self::MODULUS, Self::exp((max - 1) % Self::MODULUS, p - 1)) as _
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/problem_2266_count_number_of_texts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ mod tests {
use super::Solution;

pub fn run<S: Solution>() {
let test_cases = [("22233", 8), ("222222222222222222222222222222222222", 82_876_089)];
let test_cases = [
("22233", 8),
("222222222222222222222222222222222222", 82_876_089),
("444479999555588866", 3136),
];

for (pressed_keys, expected) in test_cases {
assert_eq!(S::count_texts(pressed_keys.to_string()), expected);
Expand Down

0 comments on commit d249dae

Please sign in to comment.