Codeforces Round #330 (Div. 2)B. Pasha and Phone 容斥
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.
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).
Print a single integer — the number of good phone numbers of length n modulo 109 + 7.
6 2
38 56 49
7 3 4
8
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
题意:给你n,k,n个ai,n个bi, 对于所有能整除ai的数中 位数小于等于k位,且最高位开头不以bi开头的数有几个,再取随机组合数
例:k=2 5是以0开头,不是以5开头
题解:我们可以算出1到n是x的倍数的个数有n/x个,那么减去一些不需要的数就是容斥了了,
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a)); inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
const double PI = 3.1415926535897932384626433832795;
const double EPS = 5e-;
#define maxn 100000+500
#define mod 1000000007 ll num[maxn],a[maxn],b[maxn],kk; int main(){
ll n=read(),k=read();
ll tmp=; kk=k;
for(int i=;i<=k;i++)tmp*=; for(int i=;i<=n/kk;i++){
scanf("%I64d",&a[i]);
}
for(int i=;i<=n/kk;i++){
scanf("%I64d",&b[i]);
}
for(ll i=;i<=n/kk;i++){
num[i]=;
if(b[i]){
int T=;
for(int j=;j<=kk-;j++)b[i]*=,T*=;
ll H=(b[i]+(T-))/a[i]-(b[i]-)/a[i];
num[i]+=(tmp-)/a[i]-H;
}
else {
num[i]+=(tmp-)/a[i]-(tmp/-)/a[i];
}
if(b[i]==)num[i]--;
}
ll ans=;
for(int i=;i<=n/kk;i++){
ans=(ans*num[i])%mod;
}
cout<<ans<<endl;
return ;
}
代码
Codeforces Round #330 (Div. 2)B. Pasha and Phone 容斥的更多相关文章
- 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/pr ...
- Codeforces Round #258 (Div. 2) E. Devu and Flowers 容斥
E. Devu and Flowers 题目连接: http://codeforces.com/contest/451/problem/E Description Devu wants to deco ...
- 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 i ...
- Codeforces Round #428 (Div. 2) D. Winter is here 容斥
D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...
- Codeforces Round #619 (Div. 2)C(构造,容斥)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int main(){ ios::syn ...
- Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和
Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...
- Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理
Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...
- Codeforces Round #337 (Div. 2) A. Pasha and Stick 数学
A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...
随机推荐
- Unity学习-软件的基本操作(二)
基本操作 1:Scene中 以小手显示,平移画布,与鼠标中键一样 2:平移 游戏对象,组件的 Position属性 也可设置 3:旋转 游戏对象,组件的 Rotation属性 也可设置 4:缩放 游戏 ...
- SpringAop--系统日志简例
通过Spring的Aop我们可以声明式的配置事务管理,那么同样可以通过SpringAop来进行处理的系统日志该如何实现呢? 一.数据表和实体类的准备 我们要管理系统日志,那么数据表和实体类是必不可少的 ...
- SQL Server应用模式之OLTP系统性能分析
OLTP系统的最大特点,是这类应用里有大量的,并发程度比较高的小事务,包括SELECT.INSERT.UPDATE和DELETE. 这些操作都比较简单,事务时间也不会很长,但是要求的返回时间很严格,基 ...
- [ ZJOI 2006 ] Trouble
\(\\\) \(Description\) 有\(N\)个人的环,每个人需要至少\(x_i\)种不同的物品,并且要求任意相邻的两人都没有相同的物品,求最少需要多少种物品. \(N\in [0,2\t ...
- 自己整理的css3动画库,附下载链接
动画调用语法 animation: bounceIn 0.3s ease 0.2s 1 both; 按顺序解释参数: 动画名称 如:bounceIn 一周期所用时间 如:0.3s 速度曲线 如:eas ...
- js indexOf 列表筛选
先来一堆效果图: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- Zynq7000系列之芯片系统结构概述
相比较经典的FPGA,Zynq7000系列最大的特点是将处理系统PS和可编程资源PL分离开来,固化了PS系统的存在,实现了真正意义上的SOC(System On Chip). 1. Zynq7000 ...
- 零基础转行Linux云计算运维工程师获得20万年薪的超级学习技巧
云计算概念一旦产生便一发不可收拾,成为移动互联网时代最为火热的行业之一.国内各大互联网公司例如阿里.腾讯.百度.网易等纷纷推出自己的云计算产品,3月10日,腾讯云0.01元投标时间更是让云计算在普罗大 ...
- vmware vSphere client中,选择文件->部署OVF模板,报错处理方法
在vmware vSphere client中,选择文件->部署OVF模板,选择指定的OVA文件,按步骤进行,则会出现这样的错误:此OVF软件包使用了不受支持的功能.OVF软件包需要不支持的硬件 ...
- 安卓手机安装charles安全证书
本次安装使用小米mix2为例. 手机浏览器上安装: 第一种: 1.首先 设置好手机的charles代理 172.16.xxx.xxx 8888 2.要使用 打开非自带浏览器(夸克/QQ/UC手 ...