const M: i64 = 1000000007; fn powmod(x: i64, y: i64, m: i64) -> i64 { if y == 0 { return 1; } let mut ans = powmod(x, y>>1, m); ans = ans * ans % m; if (y&1) == 1 { ans = ans * x % m; } ans } fn main() { let mut scanner = Scanner::new(); let b = scanner.next_i64() % M; let c = scanner.next_i64() % M; let d = scanner.next_i64(); let s = if c == 1 { d % M } else { let mut v = (powmod(c, d+1, M)-c) * powmod(c-1, M-2, M) % M; if v < 0 { v += M } v }; println!("{}", s * b % M); } struct Scanner { reader: std::io::Stdin, tokens: std::collections::VecDeque, } impl Scanner { fn new() -> Self { Scanner { reader: std::io::stdin(), tokens: std::collections::VecDeque::new(), } } fn next(&mut self) -> String { if self.tokens.is_empty() { let mut s = String::new(); loop { self.reader.read_line(&mut s).ok(); let s = s.trim(); if s.len() != 0 { for it in s.split_whitespace() { self.tokens.push_back(it.into()) } break; } } } self.tokens.pop_front().unwrap() } fn next_generics(&mut self) -> T where T: std::str::FromStr + std::marker::Copy, ::Err: std::fmt::Debug { self.next().parse().unwrap() } #[allow(dead_code)] fn next_i32(&mut self) -> i32 { self.next_generics::() } #[allow(dead_code)] fn next_i64(&mut self) -> i64 { self.next_generics::() } #[allow(dead_code)] fn next_u64(&mut self) -> u64 { self.next_generics::() } #[allow(dead_code)] fn next_usize(&mut self) -> usize { self.next_generics::() } }