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

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, ..., 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 2
38 56 49
7 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);
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/296051.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

美女晕倒怎么办?二哈:这不是一滋就醒......

1 永远不要质疑二哈▼2 睡觉也不耽误练功▼3 谁还没为数学考试受过伤呢&#xff1f;▼4 可能我的嘴巴安装了笑话过滤器吧▼5 我书读得少&#xff0c;你别吓唬我▼6 希望狗没事儿▼7 海王的微信壁纸事实证明&#xff0c;会计确实不赚钱▼你点的每个赞&#xff0c;我都认真…

linux at java,Linux-Tutorial/Java-bin.md at master · linsanityHuang/Linux-Tutorial · GitHub

Java bin 目录下的工具JVM 内存结构运行时数据区(JVM 规范)VM 栈(JVM 虚拟机栈)是线程私有的&#xff0c;它的生命周期和线程相同。它描述的是 Java 方法执行的内存模式。Java 堆区(Heap)是 Java 虚拟机所管理的内存中最大的一块。是被所有线程共享的一块内存区域&#xff0c;在…

如何在 C# 中使用 FTP 上传文件

咨询区 webvision&#xff1a;我尝试用 C# 上传一个文件到 FTP-Server 上&#xff0c;文件已显示上传成功但显示 0Byte&#xff0c;我的代码大概是这样的。private void button2_Click(object sender, EventArgs e) {var dirPath "C:/Documents and Settings/sander.GD/B…

POJ 3274 Gold Balanced Lineup(哈希)

题目链接 很难想。会哈希&#xff0c;但是想不出。需要一个转化&#xff0c;本来是求某一段上的二进制上每一位的1数目相等&#xff0c;转化为找两段相等的&#xff0c;换元可推出公式。最后注意特判。。 1 #include <iostream>2 #include <cstdio>3 #include <…

java Ant build.xml

Java Ant build.xml详解1,什么是antant是构建工具 2,什么是构建 概念到处可查到&#xff0c;形象来说&#xff0c;你要把代码从某个地方拿来&#xff0c;编译&#xff0c;再拷贝到某个地方去等等操作&#xff0c;当然不仅与此&#xff0c;但是主要用来干这个 3,ant的好处 跨平台…

15℃!人类首次实现高压下室温超导,研究登上Nature封面

全世界只有3.14 % 的人关注了爆炸吧知识本文转自&#xff1a;机器之心今天一项新纪录&#xff0c;轰动整个物理界。「室温超导有可能实现吗&#xff1f;」这个问题困惑了人们许多年。而最新一期的 Nature 杂志封面研究给出了肯定的答案&#xff0c;该研究制造出了第一个无需冷却…

系统日子打印记录

#import <Foundation/Foundation.h>//DmLog----------------------------- #define DmLog_TYPE_1 1 //日志打印 1:开/0:关 #define __DmLOGWITHFUNCTION(s, ...) \ NSLog("%s : %",__FUNCTION__,[NSString stringWithFormat:(s), #…

linux下ui c语言编程,编写的C语言程序,怎么样制作一个UI界面?

c语言制作UI界面需要相关的UI库如windows操作系统本身就提供了UI的接口一个简单的示例代码如下#include LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,LPSTR line,int cmd){ static TCHAR AppName[]TEX…

使用自定义卫语句写出更简洁的代码

前言上次&#xff0c;我们介绍了Pitcher,可以帮我们简化卫语句&#xff1a;public User(string name, int age) {Throw.When(string.IsNullOrWhiteSpace(name), new ArgumentNullException(nameof(name)));Throw.When(age < 0, new ArgumentOutOfRangeException(nameof(age)…

Struts2的ResultType和Action处理链

Struts2的ResultType和Action处理链Struts2的结果类型在struts-default.xml中定义了Struts2内置的所有可用的<result-type/> 所有的Struts2结果处理类都要直接或间接的实现com.opensymphony.xwork2.Result接口 在struts-default.xml中的<result-types/>里面&#x…

git fork

http://help.github.com/fork-a-repo/ 概要&#xff1a; 克隆别人的代码库到自己的项目中&#xff0c;可以作为子模块的形式使用&#xff0c;或二次开发 操作流程&#xff1a; 在开源项目中点击fork按钮&#xff0c;稍等一会儿&#xff0c;该项目便会拷贝一份到你的respositori…

转软件开发过程中的各种文档

在项目开发过程中&#xff0c;应该按要求编写好十三种文档&#xff0c;文档编制要求具有  针对性、精确性、清晰性、完整性、灵活性、可追溯性。   ◇ 可行性分析报告&#xff1a;     说明该软件开发项目的实现在技术上、经济上和社会因素上的可行性&#xff0c;评述 …

【ACR2015】依那西普按需维持治疗策略有效抑制RA骨破坏进展

标签: 类风湿关节炎; 依那西普; 药物减停; 复发重治 对RA疾病复发患者, 依那西普按需治疗与持续足剂量治疗是否存在疗效差异&#xff1f; Inui K, et al. ACR 2015. Presentation ID: 477. 背景/目的: 生物DMARDs&#xff08;bDMARDs&#xff09;对RA治疗而言非常重要, 尤其对…

堪称经典!这部由苏联最杰出数学家编写的数学教材,为何能大受推崇?

全世界只有3.14 % 的人关注了爆炸吧知识安德列柯尔莫哥洛夫&#xff0c;20世纪苏联最杰出的数学家&#xff0c;也是20世纪世界上为数极少的几个最有影响的数学家之一。1924年他念大学四年级时就和当时的苏联数学家辛钦一起建立了关于独立随机变量的三级数定理。1928年他得到了随…

浅议NetMQ常见模式和消息加密机制

题图来自https://www.pexels.com/概述在传统企业级开发中&#xff0c;消息队列机制已经成为一种非常常见的技术实现手段&#xff0c;而基于NetMQ则看起来有点像一朵“奇葩”&#xff0c;看起来从名字似乎是一个消息队列&#xff08;Message Quene&#xff09;&#xff0c;但事实…

linux python matplotlib 使用,python绘图工具matplotlib在linux下安装和使用

工具介绍&#xff1a;matplotlib 是Python编程语言的一个绘图库及其数值数学扩展 NumPy。它为利用通用的图形用户界面工具包&#xff0c;如Tkinter, wxPython, Qt或GTK向应用程序嵌入式绘图提供了面向对象的应用程序接口(API)。还有一个基于状态机(如开放图形库OpenGL)的程序py…

Struts2的Interceptor和Listener以及Plugin

Struts2的Interceptor和Listener以及PluginStruts2的拦截器在struts-default.xml中定义了很多拦截器&#xff0c;这些拦截器就是用来完成许多强劲功能的保证 而且可以根据已定义的若干拦截器中的某几个拦截器构建成interceptor-stack拦截器栈 其实拦截器栈还可以由拦截器栈组成…

with(nolock)简解

eg&#xff1a;select top 200 from 表A with(nolock) where 条件 为了性能&#xff0c;查询时不锁定表&#xff0c;从而达到提高查询速度的目的。 &#xff08;转&#xff09;SQL中with(nolock)详解 大家在写查询时,为了性能,往往会在表后面加一个nolock,或者是with(nolock),其…

CentOS 5.5下搭建部署独立SVN服务器全程详解

SVN服务器有2种运行方式&#xff1a; 1、独立服务器 (例如&#xff1a;svn://xxx.com/xxx)&#xff1b; 2、借助apache (例如&#xff1a;http://svn.xxx.com/xxx)&#xff1b; 为了不依赖apache&#xff0c;我选择第一种方式&#xff1a;独立的svn服务器。SVN存储版本数据也…

35岁成MIT终身教授!北大数学“黄金一代”再获大奖

全世界只有3.14 % 的人关注了爆炸吧知识18岁时满分斩获国际奥林匹克数学竞赛金牌&#xff0c;本科就读北大数院期间19门课程成绩100分、7门99分&#xff0c;35岁成为麻省理工&#xff08;MIT&#xff09;终身教授……近日&#xff0c;数学“大神”恽之玮再获国际大奖——西蒙斯…