快速幂取模爆炸怎么办

今天做题突然想到了一道题,这题真的是坑,快速幂会爆炸

在这里插入图片描述

#include <bits/stdc++.h>
typedef long long LL;
const int maxn = 5e6 + 1;
using namespace std;
LL mod = 10000000007;
LL a[10][maxn];
void init() {
    for (int i = 1; i < 10; ++i) {
        a[i][0] = 1;
        for (int j = 1; j < maxn; ++j) {
            a[i][j] = a[i][j-1] * i % mod;
        }
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);    
    init();
    int n;
    string s;
    LL ans = 0;
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; ++i) {
        ans = (ans + a[s[i]-'0'][i]) % mod; 
    }
    cout << ans << endl;
 	return 0;
}
发布了31 篇原创文章 · 获赞 13 · 访问量 756

猜你喜欢

转载自blog.csdn.net/weixin_43310882/article/details/99680046