题目内容
对于一个长度为n的十进制整数N=(b1,b2....bn)(0<=bi<=9,b1!=0),定义P(N)=b1^1 * b2^2 *....bn^n,当然这个数很大,我们只要你输出P(N)%1000000007的结果 P(123)=(1^1 * 2 ^ 2 * 3^3)mod 1000000007=108输入说明
多组输入,每一行一个数字1<=N<=10^1000000输出说明
P(N)%1000000007的结果输入样例1
123输出样例1
108提示
无
解题思路:
模拟即可
AC代码:
#![allow(warnings)]
use std::io;
use std::error::Error;
use std::boxed::Box;
use std::convert::TryInto;
use std::cmp::Ordering;
use std::cmp::min;
use std::cmp::max;
const p: u64 = 1000000007;fn pow(num: u64, j: u64) -> u64 {let mut res: u64 = 1;for i in 1 ..= j {res *= num % p;res %= p;}res
}fn getAns(str_num: &String) -> u64 {let mut res: u64 = 1;for (index, str_char) in str_num.char_indices() { if let Ok(num) = str_char.to_string().parse::<u64>() {res *= pow(num, (index + 1) as u64) as u64;res %= p as u64;}}return res;
}fn main() -> Result<(), Box<dyn Error>> {let mut cin = String::new();io::stdin().read_line(&mut cin).unwrap();print!("{}", getAns(&cin));Ok(())
}