zoukankan      html  css  js  c++  java
  • K

    K - Magic Five
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status
    Appoint description: 

    Description

    There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.

    Now Iahub wants to count the number of ways he can obtain magic number, modulo 1000000007 (109 + 7). Two ways are different, if the set of deleted positions in s differs.

    Look at the input part of the statement, s is given in a special form.

    Input

    In the first line you're given a string a (1 ≤ |a| ≤ 105), containing digits only. In the second line you're given an integer k (1 ≤ k ≤ 109). The plate s is formed by concatenating k copies of a together. That is n = |ak.

    Output

    Print a single integer — the required number of ways modulo 1000000007 (109 + 7).

    Sample Input

    Input
    1256
    1
    Output
    4
    Input
    13990
    2
    Output
    528
    Input
    555
    2
    Output
    63
    const int INF = 1000000000 + 7;
    const double eps = 1e-8;
    const int maxn = 300000;
    
    LL Pow(LL x,LL y,LL c)
    {
        if(y == 0)
            return 1;
        LL ans = Pow(x,y/2,c);
        ans = ans*ans%c;
        if(y%2)
            ans = ans*x%c;
        return ans;
    }
    char str[maxn];
    int main() 
    {
        //freopen("in.txt","r",stdin);
        while(scanf("%s",str) == 1)
        {
            int re;
            scanf("%d",&re);
            LL ans = 0;
            int len = strlen(str);
            int cnt = 0;
            rep(i,0,len)
            {
                if(str[i] == '0' || str[i] == '5')
                {
                    LL b = (Pow(2,len,INF) - 1);
                    b = Pow(b,INF-2,INF);
                    ans  = (ans + b*(Pow(2,cnt,INF)*(Pow(2,(LL)len*re,INF)- 1)%INF)%INF)%INF;
                }
                cnt++;
            }
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    【POJ 2406】Power Strings(KMP循环节)
    【HDU 3746】Simpsons’ Hidden Talents(KMP求循环节)
    【CodeForces 672B】Different is Good
    【UVALive 4642】Malfatti Circles(圆,二分)
    【POJ 1269】判断两直线相交
    【POJ 2503】Babelfish(字符串)
    ZOJ 2676 Network Wars[01分数规划]
    A1261. happiness(吴确)[二元组暴力最小割建模]
    poj3469 Dual Core CPU
    2154: Crash的数字表格
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3437740.html
Copyright © 2011-2022 走看看