Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理

    xiaoxiao2021-03-25  95

    题目链接:http://codeforces.com/contest/595/problem/B 题意:给你ai和bi,让你找到有多少个k位数,使得这个k位数不以bi开头且mod ai=0,处理n/k次,然后把所有的答案都乘起来 解法:容斥水题,所有的方案数 - 以bi开头的就好了

    //CF 595B #include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int mod = 1e9+7; long long a[maxn], b[maxn]; long long ten[20]; long long ans[maxn]; int main() { int n, k; scanf("%d%d", &n, &k); for(int i = 1; i <= n/k; i++) scanf("%lld", &a[i]); for(int i = 1; i <= n/k; i++) scanf("%lld", &b[i]); ten[0] = 1; for(int i = 1; i <= 10; i++) ten[i] = ten[i-1]*10; long long tmp1, tmp2, tmp3; for(int i = 1; i <= n/k; i++){ tmp1 = (ten[k]-1)/a[i]+1; tmp2 = ((b[i]+1)*ten[k-1]-1)/a[i]+1; if(b[i] == 0) ans[i] = tmp1-tmp2; else{ tmp3 = (b[i]*ten[k-1]-1)/a[i]+1; ans[i]=tmp1-tmp2+tmp3; } } long long Ans = 1; for(int i = 1; i <= n/k; i++){ Ans = Ans*ans[i]%mod; } printf("%lld\n", Ans); return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-21056.html

    最新回复(0)