zoukankan      html  css  js  c++  java
  • Codeforces Round #330 (Div. 2) B. Pasha and Phone

    B. Pasha and Phone
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits.

    Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer.

    To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1·10k - 1 + c2·10k - 2 + ... + ck.

    Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7.

    Input

    The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k.

    The second line of the input contains n / k space-separated positive integers — sequence a1, a2, ..., an / k (1 ≤ ai < 10k).

    The third line of the input contains n / k space-separated positive integers — sequence b1, b2, ..., bn / k (0 ≤ bi ≤ 9).

    Output

    Print a single integer — the number of good phone numbers of length n modulo 109 + 7.

    Sample test(s)
    Input
    6 2
    38 56 49
    7 3 4
    Output
    8
    Input
    8 2
    1 22 3 44
    5 4 3 2
    Output
    32400
    Note

    In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.

    题意:长度为n的串 每长度k为一个block(块)

     第二行输入 n/k个数 表示  第i块中的数必须是a[i]的倍数

     第三行输入 n/k个数 表示 第i块的首位不能为b[i]

    注意 首位为0的处理!!!

    还是水果A题 手速不行 B 字符串题目 要多练了

    #include<bits/stdc++.h>
    using namespace std;
    #define N 1000000007    
    __int64 n,k;
    __int64 a[100000];
    __int64 b[100000];
    __int64 re;
    int main()
    {
        scanf("%I64d%I64d",&n,&k);
        re=1;
        for(__int64 i=1;i<=n/k;i++)
            scanf("%I64d",&a[i]);
        for(__int64 i=1;i<=n/k;i++)
            scanf("%I64d",&b[i]);
        for(__int64 i=1;i<=n/k;i++)
        {
           __int64 exm=1;
           __int64 linshi=0;
           for(int j=1;j<=k;j++)
               exm*=10;
           if(b[i]!=0)
           linshi=linshi+(exm-1)/a[i]+1-(((b[i]+1)*(exm/10)-1)/a[i]-((b[i])*(exm/10)-1)/a[i]);
            else
           linshi=linshi+(exm-1)/a[i]-(exm/10-1)/a[i];
           re=re*linshi;
           re=re%N;
        }
        printf("%I64d",re);
        return 0;
    }
    

      

  • 相关阅读:
    Java WebService入门实例
    Maven是什么
    for 循环
    2.4 DevOps工程师的故事:构建运行时的严谨性
    2.3.3 构建微服务的入口:Spring Boot控制器
    2.3.2 引导Spring Boot应用程序:编写引导类
    2.1.3 互相交流:定义服务接口
    第2章 使用Spring Boot构建微服务
    第1章 欢迎来到Cloud和Spring
    第一次在博客园开博
  • 原文地址:https://www.cnblogs.com/hsd-/p/4950917.html
Copyright © 2011-2022 走看看