题目链接:

http://codeforces.com/problemset/problem/595/B

题意:

有一个n位的电话号码,每位电话号码将分成n/k段,每段均为k个数,求出满足以下要求的电话号码个数

1)第i段可以整除a[i];

2)第i段不能以数字b[i]开头。

解题思路:

1、 第i段能被a[i]整除的的个数z=(10^k-1)/a[i]+1;

2、 能被a[i]整除但以b[i]开头的个数y有:设 MIN=b[i]*10^(k-1),MAX=(b[i]+1)*10^(k-1)-1;

①如果MIN/a[i]*a[i]=MIN, 则y=(MAX-MIN)/a[i]+1;

  ②如果①条件不满足,如果(MIN/a[i]+1)*a[i]<=MAX, 则y=(MAX-(MIN/a[i]+1)*a[i])/a[i]+1;

通过1和2可以得出第i段满足的号码个数为c[i]=z-y;将每一段满足情况的个数求出来,将它们乘起来就可以求出所要答案。

//借鉴了大神的思路

程序代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
#define LL long long
const int M=;
LL mod=;
LL a[M],b[M],num[M];
LL n,k,sum,m,cnt; void init()
{
for(LL i=;i<=k;i++)
cnt*=;
m=cnt/;
for(int i=;i<n/k;i++)
scanf("%d",&a[i]);
for(LL i=;i<n/k;i++)
scanf("%d",&b[i]);
} void work()
{
for(LL i=;i<n/k;i++)
{
num[i]=(cnt-)/a[i]+;
LL MAX=(b[i]+)*m-;
LL MIN=b[i]*m;
LL temp=MIN/a[i];
if(temp*a[i]==MIN)
num[i]-=(MAX-MIN)/a[i]+;
else if((temp+)*a[i]<=MAX)
{
MIN=(temp+)*a[i];
num[i]-=(MAX-MIN)/a[i]+;
}
}
}
int main()
{
sum=cnt=;
cin>>n>>k;
init();
work(); for(LL i=;i<n/k;i++)
sum=((num[i]%mod)*sum)%mod; printf("%lld\n",sum%mod);
return ;
}

CodeForces 595B的更多相关文章

  1. Codeforces 595B - Pasha and Phone

    595B - Pasha and Phone 代码: #include<bits/stdc++.h> using namespace std; #define ll long long # ...

  2. Codeforces 595B. Pasha and Phone 容斥

    B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. 找出整数中第k大的数

    一  问题描述: 找出 m 个整数中第 k(0<k<m+1)大的整数. 二  举例: 假设有 12 个整数:data[1, 4, -1, -4, 9, 8, 0, 3, -8, 11, 2 ...

  2. SGU 142.Keyword

    时间限制:0.5s 空间限制:16M 题意 给出一个仅由'a',‘b’组成的字符串S,长度小于500 000,求一个由‘a’,‘b’组成的不是S子串的字符串T. 输出T的长度和T. Sample In ...

  3. 【POJ3468】【树状数组区间修改】A Simple Problem with Integers

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  4. TextView控件

    1.手动创建(不建议): TextView tv = new TextView(this); tv.setContent("你好"); setContentView(tv); 2. ...

  5. 升级10.10 Yosemite 后,cocoapods 出现错误(解决方案)

    RSMacBook-Pro:~ RS$ pod search jsonkit /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/li ...

  6. 关于使用iframe标签自适应高度的使用

    在ifrome内设定最小高度,(此方法只适用于页面内切换高度不一.但是会保留最大高度,返回后保持最大高度不再回到最初页面的高度) <iframe id="one4" widt ...

  7. ICE学习第一步-----配置ICE环境变量

    安装 ICE: 1.下载ICE: http://www.zeroc.com/download.html 下载说明:ICE支持语言(C++, Java, C#, Visual Basic,Python, ...

  8. python【第八篇】socket网络编程

    内容大纲 1.socke基础 两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket. 建 立网络通信连接至少要一对端口号(socket).socket本质是编程接口(API ...

  9. apt-cache madison package-name

    apt-cache madison package-name 搜索软件有那些可用版本,

  10. Plan-9效应:为什么东西不坏就不要去修它

    http://www.aqee.net/the-plan-9-effect-or-why-you-should-not-fix-it-if-it-aint-broken/ Plan-9是一个很棒的.很 ...