20250413 finished.
This commit is contained in:
parent
60a946e6d7
commit
fa7fa14080
|
@ -595,3 +595,5 @@ mod p3375_minimum_operations_to_make_array_values_equal_to_k;
|
|||
mod p2843_count_symmetric_integers;
|
||||
|
||||
mod p3272_find_the_count_of_good_integers;
|
||||
|
||||
mod p1922_count_good_numbers;
|
||||
|
|
49
src/problem/p1922_count_good_numbers.rs
Normal file
49
src/problem/p1922_count_good_numbers.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* [1922] Count Good Numbers
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
// submission codes start here
|
||||
|
||||
const MOD: i64 = 1_000_000_000 + 7;
|
||||
|
||||
impl Solution {
|
||||
pub fn count_good_numbers(n: i64) -> i32 {
|
||||
let mut result = Self::quick_power(20, n / 2);
|
||||
|
||||
if n % 2 == 1 {
|
||||
result = result * 5 % MOD;
|
||||
}
|
||||
|
||||
result as i32
|
||||
}
|
||||
|
||||
fn quick_power(mut m: i64, mut n: i64) -> i64 {
|
||||
let mut result = 1;
|
||||
|
||||
while n > 0 {
|
||||
if n & 1 == 1 {
|
||||
result = result * m % MOD;
|
||||
}
|
||||
|
||||
m = m * m % MOD;
|
||||
n = n >> 1;
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_1922() {
|
||||
assert_eq!(5, Solution::count_good_numbers(1));
|
||||
assert_eq!(400, Solution::count_good_numbers(4));
|
||||
assert_eq!(564_908_303, Solution::count_good_numbers(50));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user