codeforces 300 div2 B.Pasha and Phone 容斥原理
1 second
256 megabytes
standard input
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, ..., 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
8 2
1 22 3 44
5 4 3 2
32400
题意:一个电话号码分成K块,每块的开头不能是b[i],每块应该是a[i]的倍数;
思路;将每块a[i]的总数求出来,再减去以b[i]开头的a[i]倍数的个数;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define pi 4*atan(1)
//#pragma comment(linker, "/STACK:102400000,102400000")
#define maxn (1<<18)
const int N=;
ll a[N],b[N];
ll num[N];
ll f(ll x)
{
ll sum=;
for(ll i=;i<x;i++)
sum*=;
return sum;
}
int main()
{
ll x,y,z,i,t;
while(~scanf("%I64d%I64d",&x,&y))
{
ll base=f(y);
for(i=;i<x/y;i++)
scanf("%I64d",&a[i]);
for(i=;i<x/y;i++)
scanf("%I64d",&b[i]);
for(i=;i<x/y;i++)
{
ll num1=(base-)/a[i]+;
ll num2=((b[i]+)*(base/)-)/a[i]+(b[i]==?:);
ll num3=(b[i]*(base/)-)/a[i];
num3=max(0LL,num3);
num[i]=num1-num2+num3;
}
ll ans=;
for(i=;i<x/y;i++)
ans*=num[i],ans%=mod;
printf("%I64d\n",ans);
}
return ;
}
最新文章
- Nginx的安装配置
- 搭建高可用mongodb集群(四)—— 分片
- hdoj 1002 A+B(2)
- 《Unix网络编程》卷一(简介TCP/IP、基础套接字编程)
- AD 10 直接出 BOM 的漂亮效果
- Oracle修改字段长度以及计算天数
- Android 数据过滤器:Filter
- 看看android基础知识,谁帮我作答
- ES 13 - Elasticsearch的元字段 (_index、_type、_source、_routing等)
- 论文阅读笔记四十一:Very Deep Convolutional Networks For Large-Scale Image Recongnition(VGG ICLR2015)
- Java 线程方法
- Docker(三)Docker是如何工作的
- 超级有用的15个mysqlbinlog命令
- ubuntu文件名乱码convmv和iconv
- 关于string.Template的简单介绍
- QTP之回放模式(ReplayType)
- a标签--超链接
- leetcode 有效的括号
- (C/C++) 指向函數的指標
- HDU4788_Hard Disk Drive
热门文章
- 电力项目十七--数据字典首页JS添加和删除表格
- Python 自学积累(二)
- Centos6.5安装JDK环境
- java 中的&; &;&;区别以及 C++ 中&; &;&;的区别
- Apache POI 读写 Excel 文件
- You don&#39;t have permission to access
- python bug the C library strftime function.
- mongoexport
- talib 中文文档(九):# Volatility Indicator Functions 波动率指标函数
- Django - ORM - 进阶