Codeforces Round #330 (Div. 2) 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
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;
}
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 #330 (Div. 2)B. Pasha and Phone 容斥
B. Pasha and Phone Pasha has recently bought a new phone jPager and started adding his friends' ph ...
- 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 #337 (Div. 2) A. Pasha and Stick 数学
A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...
- 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 ...
- Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting
B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone ...
- Codeforces Round #330 (Div. 2)
C题题目出错了,unrating,2题就能有很好的名次,只能呵呵了. 水 A - Vitaly and Night /***************************************** ...
- Codeforces Round #337 (Div. 2) A. Pasha and Stick 水题
A. Pasha and Stick Pasha has a wooden stick of some positive integer length n. He wants to perform ...
随机推荐
- Python3获取新浪微博内容乱码问题
用python获取新浪微博最近发布内容的时候调用 public_timeline()函数的返回值是个jsonDict对象,首先需要将该对象通过json.dumps函数转换成字符串,然后对该字符串用GB ...
- Python3.5 Keras-Theano(含其他库)windows 安装环境
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Windows-x86.execonda --version ...
- LeetCode - 136. Single Number - ( C++ ) - 解题报告 - 位运算思路 xor
1.题目大意 Given an array of integers, every element appears twice except for one. Find that single one. ...
- truffle运行特殊 无法找到module的处理方法
https://blog.csdn.net/SnWJy/article/details/80549227 错误描述: truffle项目根目录执行truffle compile时,报错'modul ...
- #pragma pack(n)对齐格式
#pragma pack(n)对齐格式 #pragma pack(n) 是预处理器用来指定对齐格式的指令,表示n对齐.当元素字节小于n时,要扩展到n:若元素字节大于n则占用其实际大小. struct ...
- POJ 2455 Secret Milking Machine(最大流+二分)
Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...
- 【树莓派 Raspberry-Pi 】系统安装及一些必要的配置
上周六刚收到我的小电脑,被无线设置卡住了,文章并非原创,参考了几个朋友的折腾经历,自己整理下备忘,也希望能帮到和我一样在树莓派方面小白的人,也希望可以和更多有这方面兴趣的朋友共同交流 0. 操作系统下 ...
- Android UI 设计之 TextView EditText 组件属性方法最详细解析
. 作者 :万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18964835 . TextView 相关类的继承结构 ...
- P4语法(2) Parser
这里参考学习了: P4语言规范 P4台湾社群 Parser 关于parser 在P4程序中,有着大量的首部(header)和首部实例,但每次只有部分首部实例会对数据包进行操作,而parser会用于生成 ...
- Spring学习(三)—— 自动装配案例分析
Spring_Autowiring collaborators 在Spring3.2.2中自动装配类型,分别为:no(default)(不采用自动装配).byName,byType,construct ...