/** * _ _ __ _ _ _ _ _ _ _ * | | | | / / | | (_) | (_) | | (_) | | * | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___| |_ ___ * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __| * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ V / __/ | | | |_| \__ \ |_ \__ \ | | | | |_) | |_) | __/ |_\__ \ * |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___| |_| \__,_|___/\__| |___/_| |_|_| .__/| .__/ \___|\__|___/ * | | | | | | * |_| |_| |_| * * https://github.com/hatoo/competitive-rust-snippets */ #[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::io::{stdin, stdout, BufWriter, Write}; #[allow(unused_imports)] use std::iter::FromIterator; mod util { use std::fmt::Debug; use std::io::{stdin, stdout, BufWriter, StdoutLock}; use std::str::FromStr; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn chars() -> Vec { line().chars().collect() } #[allow(dead_code)] pub fn gets() -> Vec where ::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn with_bufwriter) -> ()>(f: F) { let out = stdout(); let writer = BufWriter::new(out.lock()); f(writer) } } #[allow(unused_macros)] macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } const BIG_STACK_SIZE: bool = true; #[allow(dead_code)] fn main() { use std::thread; if BIG_STACK_SIZE { thread::Builder::new() .stack_size(32 * 1024 * 1024) .name("solve".into()) .spawn(solve) .unwrap() .join() .unwrap(); } else { solve(); } } #[allow(dead_code)] pub const M: u64 = 1_000_000_007; #[allow(dead_code)] pub fn gcd(a: u64, b: u64) -> u64 { if b == 0 { a } else { gcd(b, a % b) } } #[allow(dead_code)] pub fn lcm(a: u64, b: u64) -> u64 { a / gcd(a, b) * b } #[allow(dead_code)] /// (gcd, x, y) pub fn extgcd(a: i64, b: i64) -> (i64, i64, i64) { if b == 0 { (a, 1, 0) } else { let (gcd, x, y) = extgcd(b, a % b); (gcd, y, x - (a / b) * y) } } #[allow(dead_code)] pub fn mod_pow(x: u64, n: u64, m: u64) -> u64 { let mut res = 1; let mut x = x % M; let mut n = n; while n > 0 { if n & 1 == 1 { res = (res * x) % m; } x = (x * x) % m; n >>= 1; } res } #[allow(dead_code)] pub fn mod_inverse(a: u64, m: u64) -> u64 { let (_, x, _) = extgcd(a as i64, m as i64); ((m as i64 + x) as u64 % m) % m } #[allow(dead_code)] pub fn fact_table(len: usize, m: u64) -> Vec { let mut res = vec![1; len + 1]; for i in 1..len + 1 { res[i] = (i as u64 * res[i - 1]) % m; } res } #[allow(dead_code)] /// Factorial and Inverse factorial table pub fn fact_inv_table(size: usize, m: u64) -> (Vec, Vec) { let mut fact = vec![1; size]; let mut fact_inv = vec![1; size]; for i in 2..size { fact[i] = fact[i - 1] * i as u64 % m; fact_inv[i] = m - ((m / i as u64) * fact_inv[(m % i as u64) as usize] % m); } for i in 1..size { fact_inv[i] = fact_inv[i - 1] * fact_inv[i] % m; } (fact, fact_inv) } #[allow(dead_code)] /// (a mod p, e when n! = a p\^e) pub fn mod_fact(n: u64, p: u64, fact: &[u64]) -> (u64, u64) { if n == 0 { (1, 0) } else { let (a, b) = mod_fact(n / p, p, fact); let pow = b + n / p; if n / p % 2 != 0 { (a * (p - fact[(n % p) as usize]) % p, pow) } else { (a * fact[(n % p) as usize] % p, pow) } } } #[allow(dead_code)] /// C(n, k) % p pub fn mod_comb(n: u64, k: u64, p: u64, fact: &[u64]) -> u64 { if n < k { 0 } else { let (a1, e1) = mod_fact(n, p, fact); let (a2, e2) = mod_fact(k, p, fact); let (a3, e3) = mod_fact(n - k, p, fact); if e1 > e2 + e3 { 0 } else { a1 * mod_inverse(a2 * a3 % p, p) % p } } } #[allow(dead_code)] /// H(n, k) % p pub fn mod_comb_repetition(n: u64, k: u64, p: u64, fact: &[u64]) -> u64 { mod_comb(n - 1 + k, n - 1, p, fact) } fn solve() { let (b, c, d) = get!(u64, u64, u64); if c == 1 { println!("{}", (b % M) * (d % M) % M); return; } let u = ((mod_pow(c, d, M) + M - 1) % M) * (c % M) % M; let d = mod_inverse(c - 1, M); println!("{}", ((((b % M) * u) % M) * d) % M); }