B. Pasha and Phone

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/595/problem/B

Description

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, ..., 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.

Under two situations the player could score one point.

⋅1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won't get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.

⋅2. Ignoring the buoys and relying on dogfighting to get point. If you and your opponent meet in the same position, you can try to fight with your opponent to score one point. For the proposal of game balance, two players are not allowed to fight before buoy #2 is touched by anybody.

There are three types of players.

Speeder: As a player specializing in high speed movement, he/she tries to avoid dogfighting while attempting to gain points by touching buoys.
Fighter: As a player specializing in dogfighting, he/she always tries to fight with the opponent to score points. Since a fighter is slower than a speeder, it's difficult for him/her to score points by touching buoys when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.

There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting. Since Asuka is slower than Shion, she decides to fight with Shion for only one time during the match. It is also assumed that if Asuka and Shion touch the buoy in the same time, the point will be given to Asuka and Asuka could also fight with Shion at the buoy. We assume that in such scenario, the dogfighting must happen after the buoy is touched by Asuka or Shion.

The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

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 Input

6 238 56 497 3 4

Sample Output

8

HINT

题意

给你ai和bi,让你找到有多少个k位数,使得这个k位数不以bi开头且mod ai=0

处理n/k次,然后把所有的答案都乘起来

题解:

容斥定理,所有的方案数 - 以bi开头的就好了

代码

#include<iostream>
#include<stdio.h>
using namespace std;
#define maxn 100005
const int mod = 1e9 + 7;
long long a[maxn],b[maxn];
long long ten[20];
long long ans[maxn];
int main()
{int n,k;scanf("%d%d",&n,&k);for(int i=1;i<=n/k;i++)scanf("%lld",&a[i]);for(int i=1;i<=n/k;i++)scanf("%lld",&b[i]);ten[0]=1;for(int i=1;i<=10;i++)ten[i]=ten[i-1]*10;long long tmp1,tmp2,tmp3;for(int i=1;i<=n/k;i++){tmp1 = (ten[k]-1)/a[i]+1;tmp2 = ((b[i]+1)*ten[k-1]-1)/a[i]+1;if(b[i]==0)ans[i]=tmp1-tmp2;else{tmp3 = ((b[i])*ten[k-1]-1)/a[i]+1;ans[i]=tmp1-tmp2+tmp3;}}long long Ans = 1;for(int i=1;i<=n/k;i++)Ans = (Ans * ans[i])%mod;printf("%lld\n",Ans);
}

Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理相关推荐

  1. Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题

    B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/prob ...

  2. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and Phone Pasha has recently bought a new phone jPager and started adding his friends' phon ...

  3. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and Phone Pasha has recently bought a new phone jPager and started adding his friends' phon ...

  4. 模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels

    题目传送门 1 /* 2 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0 3 很挫的判断四个方向是否OK 4 */ 5 #incl ...

  5. Codeforces Round #694 (Div. 1 + Div2)(A ~ H,8题全,超高质量题解)【每日亿题】2021/2/1、2/2

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #694 (Div. 1 + Div2)(A ~ ...

  6. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  7. (6/6) Codeforces Round #694 (Div. 2)

    (6/6) Codeforces Round #694 (Div. 2) A. Strange Partition 题意: 给一个数组,数组中的所有元素可以任意合并,求数组的每个元素除以x上去整的和, ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. Spring定时器--时间设置规则
  2. oracle收集统计计划,oracle收集统计信息之analyze
  3. AOP基本概念、AOP底层实现原理、AOP经典应用【事务管理、异常日志处理、方法审计】...
  4. [codevs 2926] 黑白瓷砖(2002年安徽省队选拔赛)
  5. android悬浮功能实现,Android实现系统级悬浮按钮
  6. oracle 修改序列末值,当ViewModel值更改时,用户界面未更新
  7. 有哪些闷声发大财的行业?
  8. 《MFC游戏开发》笔记十 游戏中的碰撞检测进阶:地图类型障碍物判定
  9. python读二进制文件博客园_python二进制读写文件
  10. Effective C++ -----条款42:了解typename的双重意义
  11. 二叉树遍历算法之三:后序遍历
  12. python画图程序没有图_Python实现画图软件功能方法详解
  13. ps怎么做出针式打印机打印效果字体?
  14. python ddos攻击器
  15. Android阿面试积累,讲的真透彻
  16. 响应式与自适应设计:设计师的最佳选择是什么?
  17. JVM--GC相关记录
  18. 城市水文防汛监测预警系统解决方案
  19. Windows XP Embedded (XPE)开发工具、升级包、中文包等微软官方下载地址
  20. 中小企业如何实施知识管理策略?

热门文章

  1. 整理iOS9适配中出现的坑
  2. IOS Table中Cell的重用reuse机制分析
  3. 老歌新唱--使用VB6开发的ActiveX实现.NET程序的混淆加密
  4. c++ map用法_Python的 5 种高级用法,效率提升没毛病
  5. [Docker]记一次使用jenkins将镜像文件推送到Harbor遇到的问题
  6. python正则中如何匹配汉字以及encode(‘utf-8’)和decode(‘utf-8’)的互转
  7. Couchbase概述
  8. 配置mysql为主主复制步骤
  9. Java研发方向如何准备BAT技术面试答案(上)
  10. Processing编译android的apk应用