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;
    }
  • 相关阅读:
    IDEA 配置
    从一个多项目Web工程看Eclipse如何导入Gradle项目
    mac java环境变量配置
    gradle多项目构建及依赖
    gradle新建工程,多项目依赖,聚合工程
    JSTL的一些使用规范,坑
    mysql主从配置
    windows系统常用软件及配置介绍
    mac必装工具以及mac使用介绍
    一种480 MHz无线数传模块的设计
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3437740.html
Copyright © 2011-2022 走看看