CF 191 div2 C

这倒题找出规律不难,关键是有mod运算,还要求等比数列,直接用公式求,存在除法,不行,所以采用二分的方式。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
typedef long long LL;
using namespace std;
const int maxn = 500 + 5;
const int Mod = 1000000000 + 7;

string s;
LL k,q;

LL power(LL x,LL num){
    if(num == 0) return 1;
    if(num == 1) return x;
    LL tem = power(x,num/2);
    if(num % 2 == 1) return ((tem * tem) % Mod * x) % Mod;
    else return (tem * tem) % Mod;
}

LL sum(LL x){
    if(x == 1) return 1;
    LL tem = sum(x/2);
    if(x%2 == 1) return ((tem * (1 + power(q,x/2))) % Mod + power(q,x-1)) % Mod;
    else return (tem * (1 + power(q,x/2))) % Mod;
}

int main(){
    while(cin >> s >> k){
        LL a = 0;
        LL n = s.length();
        for(int i = 0;i < n;i++){
            if(s[i] == '0' || s[i] == '5'){
                a = (a + power(2,i)) % Mod;
            }
        }
        q = power(2,n);
        cout << (a * sum(k)) % Mod << endl;
    }
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值