complete at jungol 1077.py 3135.py 14020.py 3006.rs
This commit is contained in:
28
storage/jungol/rs/completed/3006.rs
Normal file
28
storage/jungol/rs/completed/3006.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use std::io::{read_to_string, stdin};
|
||||
|
||||
fn main() {
|
||||
let temp = read_to_string(stdin()).unwrap();
|
||||
let mut iter = temp
|
||||
.split_ascii_whitespace()
|
||||
.map(|x| x.parse::<usize>().unwrap());
|
||||
|
||||
let (n, m) = (iter.next().unwrap(), iter.next().unwrap());
|
||||
|
||||
let mut cumf = 2 % m;
|
||||
let (mut f1, mut f2) = (1 % m, 1 % m);
|
||||
|
||||
if n == 1 {
|
||||
println!("{}", f1);
|
||||
} else if n == 2 {
|
||||
println!("{}", cumf);
|
||||
} else {
|
||||
for _ in 3..=n {
|
||||
let newf = (f2 + f1) % m;
|
||||
cumf += newf;
|
||||
cumf %= m;
|
||||
f1 = f2;
|
||||
f2 = newf;
|
||||
}
|
||||
println!("{}", cumf);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user