【HDOJ】4704 Sum

时间:2021-05-21 01:14:34

数学题。f(n) = 2^(n-1) mod (1e9+7)。

 #include <cstdio>

 #define MAXN 100005

 char buf[MAXN];
__int64 phi = 1e9+;
__int64 mod = 1e9+; __int64 power2(__int64 n) {
__int64 ret = , base = ; --n;
while (n) {
if (n & )
ret = ret * base % mod;
base = base*base%mod;
n >>= ;
}
return ret;
} int main() {
__int64 tmp;
__int64 i, j; while (scanf("%s", buf) != EOF) {
tmp = ;
for (i=; buf[i]; ++i) {
tmp = *tmp + (buf[i]-'');
tmp %= phi;
}
tmp += phi;
tmp = power2(tmp);
printf("%I64d\n", tmp);
} return ;
}