CodeForces 595B Pasha and Phone
来源:互联网 发布:centos7修改ssh端口号 编辑:程序博客网 时间:2024/06/07 12:15
CodeForces 595B Pasha and Phone
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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)
To represent the block of length k as an integer, let’s write it out as a sequence
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
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
The third line of the input contains n / k space-separated positive integers — sequence
Output
Print a single integer — the number of good phone numbers of length n modulo
Sample Input
Input
6 2
38 56 49
7 3 4
Output
8
Input
8 2
1 22 3 44
5 4 3 2
Output
32400
Hint
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698
链接在这: 题目链接
题意:求n位且满足以下两点的号码数量
把号码分成k份(可能以0开头)
1. 第i份是
2. 第i份不能是以
按份for循环找一遍,再取模相乘
注意讨论
代码:
#include<stdio.h>#define mod 1000000007int a[100005];int b[100005];int ans[100005];long long mypow(int a,int b){ long long ans=1; for(int i=0; i<b; i++) ans*=10; return ans;}int main(){ int n,k; while(~scanf("%d %d",&n,&k)) { for(int i=0; i<n/k; i++) scanf("%d",&a[i]); for(int i=0; i<n/k; i++) scanf("%d",&b[i]); for(int i=0; i<n/k; i++) { if(b[i]==0) { ans[i]+=((mypow(10,k)-1)/a[i])+1; ans[i]-=(mypow(10,k-1)-1)/a[i]+1; } else { ans[i]+=((mypow(10,k)-1)/a[i])+1; ans[i]-=(mypow(10,k-1)*(b[i]+1)-1)/a[i]-(mypow(10,k-1)*(b[i])-1)/a[i]; } } long long ans2=1; for(int i=0; i<n/k; i++) { ans2*=ans[i]; ans2%=mod; } printf("%lld\n",ans2); } return 0;}
- CodeForces 595B Pasha and Phone
- CodeForces 595B Pasha and Phone
- Codeforces 595 B. Pasha and Phone【数学】
- Codeforces 595B Pasha and Phone 【数学计数】
- Codeforces 595 B. Pasha and Phone (容斥)
- Codeforces Round #330 (Div. 2)B Pasha and Phone
- CodeForces - 595B Pasha and Phone (数学技巧)好题
- codeforces B. Pasha and String
- coderforce 595B. Pasha and Phone(容斥原理)
- Codeforces Round #330 (Div. 2) B. Pasha and Phone(容斥原理)
- Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理
- Codeforces Round#297 B. Pasha and String
- Codeforces#297 B Pasha and Strini
- codeforces-525B Pasha and String
- codeforces 525B Pasha and String
- codeforces B. Pasha and Tea二分
- codeforces 525b Pasha and String
- CodeForces#311 B. Pasha and Tea
- list_tree利用php引用
- java.lang.ClassCastException: org.hibernate.impl.SQLQueryImpl cannot be cast to java.util.List
- Color-based object detection using Hue and Saturation thresholding
- Picasso如何直接加载缓存中的图片
- STF -- 数据库定义
- CodeForces 595B Pasha and Phone
- 【Spring4揭秘 基础4】国际化--MessageSource
- 【mysql】关联子查询的一种优化
- Spring-IoC的简单使用及bean的作用域属性
- hdu 3657(最小割求解最大点权独立集)
- fatal error C1189: #error : WRL requires NTDDI_VERSION to be #defined at least
- 常用三角函数公式
- 记一个复制黏贴的功能想法(黏贴剪切板中的数字自增,复制黏贴自增)
- PullrefreshLibrary(PullToRefreshGridView)上拉刷新,下拉加载+异步AsyncTask(二)