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;
    }
  • 相关阅读:
    详解Bootstrap进度条组件
    详解Bootstrap缩略图组件及警示框组件
    详解Bootstrap表单组件
    spring注解-@Autowired。@Resource。@Service
    spring注解-@Transactional事务几点注意
    17_8_9 Spring 注入
    MySQL常用语句
    Mysql 远程登录及常用命令
    数据库(外键及其约束理解)
    C语言队列(数组内核)
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3437740.html
Copyright © 2011-2022 走看看