fn read_vec() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn main() { let input:Vec = read_vec(); let result = no1004(input[0], input[1], input[2], input[3]); println!("{} {}", result.0, result.1); } fn no1004(a:usize, b:usize, x0:usize, n:usize) -> (usize, usize) { let mut x = x0; let mut player1 = (0,0,0); // pos,white,black let mut player2 = (0,0,0); // pos,white,black let get_score = |player:(usize,usize,usize)| { if player.1 > player.2 { player.2 } else { player.1 } }; for i in 0..n*2 { x = a * x + b; let dice = x % 6 + 1; if i % 2 == 0 { player1.0 += dice; if player1.0 % 2 == 0 { player1.1 = player1.1 + 1; } else { player1.2 = player1.2 + 1; } } else { player2.0 += dice; if player2.0 % 2 == 0 { player2.1 = player2.1 + 1; } else { player2.2 = player2.2 + 1; } } } (get_score(player1), get_score(player1)) }