use std::io::*; const MOD: u64 = 1_000_000_007; // mul(a_x*y, b_z*w) = c_x*w fn mul(a: Vec>, b: Vec>) -> Vec> { let mut res: Vec> = vec![vec![0; b[0].len()]; a.len()]; for i in 0..a.len() { for j in 0..b[0].len() { let mut val = 0; for k in 0..b.len() { val += a[i][k] * b[k][j] % MOD; val %= MOD; } res[i][j] = val; } } res } // 正方行列のみ fn pow(mut a: Vec>, mut e: u64) -> Vec> { let mut res: Vec> = vec![vec![0; a.len()]; a.len()]; for i in 0..a.len() { res[i][i] = 1; } while e > 0 { if e & 1 == 1 { res = mul(res, a.clone()); } a = mul(a.clone(), a.clone()); e >>= 1; } res } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let b: u64 = itr.next().unwrap().parse::().unwrap() % MOD; let c: u64 = itr.next().unwrap().parse::().unwrap() % MOD; let d: u64 = itr.next().unwrap().parse().unwrap(); let mat1 = [[c, b].to_vec(), [0, 1].to_vec()].to_vec(); let mat2 = [[b].to_vec(), [1].to_vec()].to_vec(); let mat3 = pow(mat1, d); let mat4 = mul(mat3, mat2); println!("{}", (mat4[0][0] + MOD - b) % MOD); }