超级幂积【rust题解】

题目内容

对于一个长度为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代码:
rust 复制代码
#![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(())
}
相关推荐
Ulyanov6 小时前
刚体动力学方程——牛顿-欧拉与陀螺效应的奥秘
开发语言·python·目标跟踪·雷达电子对抗·导引头
哈里沃克6 小时前
编译与链接 - 02
算法
巴糖6 小时前
Embedding了解一些
算法
罗超驿6 小时前
15.Java异常处理:从束手无策到从容应对
java·开发语言
战族狼魂6 小时前
广东备案大模型超百款
人工智能·算法·大模型·大语言模型
_kerneler6 小时前
cgroup :限制cpu原理
java·服务器·前端
千桐科技6 小时前
🚀 qModel 算法模型平台v1.2.0 开源版发布!Python 模型接入链路全面升级,告别“能跑但上不了线”的尴尬
后端·算法·llm
刘沅6 小时前
LeetCode 93.复原IP地址
算法·面试
MoonBit月兔6 小时前
MoonBit v0.10.4版本更新
开发语言·人工智能·编程·moonbit
小樱花的樱花6 小时前
Linux 多线程编程:互斥锁(Mutex)详解
linux·c语言·开发语言