use std::io::Read; fn main() { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); let x: u32 = iter.next().unwrap().parse().unwrap(); iter.next(); let mut answers: Vec = vec![1]; let mut cur_num: u32 = x; while cur_num != 1 { answers.push(cur_num); cur_num = cur_num * x % 1000003; } let len: usize = answers.len(); let answer = iter .map(|e| e.parse::().unwrap()) .fold(0, |acc, e| acc + answers[e%len]) % 1000003; println!("{}", answer); }