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;
    }
  • 相关阅读:
    NYOJ之Fibonacci数
    NYOJ之奇偶数分离
    NYOJ之喷水装置(一)
    借助LinkedHashMap实现基于LRU算法缓存
    素数距离问题
    NYOJ之ASCII码排序
    《Thinking in Java》十七章_容器深入研究_练习14(Page486)
    《Thinking in Java》十七章_容器深入研究_练习12(Page484)
    《Thinking in Java》十七章_容器深入研究_练习13(Page484)
    遍历目录
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3437740.html
Copyright © 2011-2022 走看看