complete at jungol 1077.py 3135.py 14020.py 3006.rs

This commit is contained in:
2026-07-29 22:28:56 +09:00
parent 8f06210897
commit 6a4ee13ce2
4 changed files with 95 additions and 0 deletions

View 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);
}
}