Codeforces 595B Pasha and Phone [수학 계수]

4072 단어 수학.codeforces
B. Pasha and Phone
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
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 k).
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 test(s)
input
6 2
38 56 49
7 3 4

output
8

input
8 2
1 22 3 44
5 4 3 2

output
32400

Note
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
제목: 현재 길이가 n인 빈 번호로 정수 k(n% k==0 만족)와 n/k 요소를 가진 서열 a[]와 b[]를 정합니다.
하나의 전화번호를 good로 정의합니다: 길이 n을 n/k 블록으로 나누고 i블록에 a[i]의 배수를 채워야 하며 b[i]로 시작할 수 없습니다. k자리 앞에 없으면 0을 보충할 수 있습니다.
굿 전화번호의 개수% (1e9+7)를 묻는다.
사고방식: 앞에서 뒤로 한 번 훑어보면 된다.
게으름 피우다 pow () 함수
AC 코드:
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (50000000)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d
", (a)) #define Pf(a) printf("%lf
", (a)) #define Pl(a) printf("%lld
", (a)) #define Ps(a) printf("%s
", (a)) #define W(a) while(a--) #define CLR(a, b) memset(a, (b), sizeof(a)) #define MOD 1000000007 #define LL long long #define lson o<<1, l, mid #define rson o<<1|1, mid+1, r #define ll o<<1 #define rr o<<1|1 using namespace std; LL f[10]; void getfac() { f[0] = 1; for(int i = 1; i <= 9; i++) f[i] = f[i-1] * 10; } LL a[MAXN], b[MAXN]; int main() { getfac(); int n, k; Ri(n); Ri(k); for(int i = 0; i < n / k; i++) Rl(a[i]); for(int i = 0; i < n / k; i++) Rl(b[i]); LL ans = 1; for(int i = 0; i < n / k; i++) { LL num1 = (f[k]-1) / a[i] + 1; LL num2 = (f[k-1]-1) / a[i] + 1; LL num3 = (f[k-1]*(b[i]+1)-1) / a[i] + 1 - (f[k-1]*b[i]-1) / a[i] - 1; if(b[i] == 0) ans *= num1-num2; else ans *= num1-num3; ans %= MOD; } Pl(ans); return 0; }

좋은 웹페이지 즐겨찾기