Digit Division

Time limit: 1 s Memory limit: 512 MiB

We are given a sequence of n decimal digits. The sequence needs to be partitioned into one or more contiguous subsequences such that each subsequence, when interpreted as a decimal number, is divisible by a given integer m.

Find the number of different such partitions modulo 109 + 7. When determining if two partitions are different, we only consider the locations of subsequence boundaries rather than the digits themselves, e.g. partitions 2|22 and 22|2 are considered different.

Input

The first line contains two integers n and m (1 ≤ n ≤ 300 000, 1 ≤ m ≤ 1 000 000) – the length of the sequence and the divisor respectively. The second line contains a string consisting of exactly n digits.

Output

Output a single integer – the number of different partitions modulo 109 + 7.

Example

input

4 2

1246

output

4

input

4 7

2015

output

0

//题意: n 位长的十进制数字,在其中可以任意插入分割线,分割后,要使每一段不为空,并且可以整除 m ,合法分割的方案数

//题目是极其简单的,如果前一部分可以整除 m ,那么,这部分乘10的x次方后依然可以整除,然后算出所有可分割的位置后

C(0,all),C(1,all)+...+C(all,all);  这些必然合法

= 2^all

但是,此题如果没想清楚,写代码会进坑,此题是对方案数取模,all 是%m==0的方案数,进了坑半天想不出来,唉,还是太菜啊,一度wa在第三组,真是日狗了

 # include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
# pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
# define LL long long
# define pr pair
# define mkp make_pair
# define lowbit(x) ((x)&(-x))
# define PI acos(-1.0)
# define INF 0x3f3f3f3f
# define eps 1e-
# define MOD inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
# define MX
/**************************/
char num[MX]; LL qk_mi(LL base,LL x)
{
LL res = ;
while (x)
{
if (x%==) res = (res*base)%MOD;
base=base*base%MOD;
x/=;
}
return res;
} int main()
{
int n,m;
while (scanf("%d%d",&n,&m)!=EOF)
{
scanf("%s",num);
LL zuo = ;
LL all = ;
for (int i=;i<n;i++)
{
zuo=(zuo*+(num[i]-''))%m;
if (zuo%m==) all++;
}
all--;
if (zuo%m!=)
printf("0\n");
else
{
LL ans = qk_mi(,all);
printf("%lld\n",ans);
}
}
return ;
}

Digit Division的更多相关文章

  1. UVALive 7327 Digit Division (模拟)

    Digit Division 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/D Description We are given ...

  2. BZOJ 4421: [Cerc2015] Digit Division

    4421: [Cerc2015] Digit Division Time Limit: 1 Sec  Memory Limit: 512 MBSubmit: 348  Solved: 202[Subm ...

  3. BZOJ 4421: [Cerc2015] Digit Division 排列组合

    4421: [Cerc2015] Digit Division 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4421 Descripti ...

  4. 【BZOJ4421】[Cerc2015] Digit Division 动态规划

    [BZOJ4421][Cerc2015] Digit Division Description 给出一个数字串,现将其分成一个或多个子串,要求分出来的每个子串能Mod M等于0. 将方案数(mod 1 ...

  5. Digit Division(排列组合+思维)(Gym 101480D )

    题目链接:Central Europe Regional Contest 2015 Zagreb, November 13-15, 2015 D.Digit Division(排列组合+思维) 题解: ...

  6. BZOJ4421 : [Cerc2015] Digit Division

    如果两个相邻的串可行,那么它们合并后一定可行,所以求出所有可行的串的个数$t$,则$ans=2^{t-1}$. 注意特判整个串不可行的情况,这个时候答案为0. #include<cstdio&g ...

  7. [CERC2015]Digit Division

    题目描述 We are given a sequence of n decimal digits. The sequence needs to be partitioned into one or m ...

  8. BZOJ 4421: [Cerc2015] Digit Division(思路)

    传送门 解题思路 差点写树套树...可以发现如果几个数都能被\(m\)整除,那么这几个数拼起来也能被\(m\)整除.同理,如果一个数不能被\(m\)整除,那么它无论如何拆,都无法拆成若干个可以被\(m ...

  9. Gym - 101480 CERC 15:部分题目题解(队内第N次训练)

    -------------------题目难度较难,但挺有营养的.慢慢补. A .ASCII Addition pro:用一定的形式表示1到9,让你计算加法. sol:模拟. solved by fz ...

随机推荐

  1. POJ 2942 Knights of the Round Table 黑白着色+点双连通分量

    题目来源:POJ 2942 Knights of the Round Table 题意:统计多个个骑士不能參加随意一场会议 每场会议必须至少三个人 排成一个圈 而且相邻的人不能有矛盾 题目给出若干个条 ...

  2. INSTALL_FAILED_OLDER_SDK

    Uploading file local path: /Users/Rubert/Android/workspace/MyApplication/app/build/outputs/apk/app-d ...

  3. LIME:模型预測结果是否值得信任?

    花了一天时间对LIME论文:http://arxiv.org/pdf/1602.04938v1.pdf 细致阅读和代码阅读,实验.大体理解了作者的设计思路. 背景: 我们在建立模型的时候,常常会思考我 ...

  4. C# 播放H264裸码流

    要播放H264裸码流,可以分拆为以下三个工作: 1.解码H264裸码流获取YUV数据 2.将YUV数据转换为RGB数据填充图片 3.将获取的图片进行显示 要完成工作1,我们可以直接使用海思的解码库,由 ...

  5. TCP/IP ---封装与分用

    封装 当应用程序用T C P传送数据时,数据被送入协议栈中,然后逐个通过每一层直到被当作一串比特流送入网络.其中每一层对收到的数据都要增加一些首部信息(有时还要增加尾部信息),该过程如图1 - 7所示 ...

  6. 客户端与服务端Post报文构造请求及Http Post与Get请求方法

    客户端 namespace Client.Controllers { public class HomeController : Controller { // // GET: /Home/ publ ...

  7. 妙味云课堂之css:其它知识点汇总

    一. 热区 map 热区.area 点击区域 shape="circle" 圆型,coords="圆心点X.圆心点Y,圆的半径" shape="rec ...

  8. MySql多对多关系中外键的应用

    业务需求:用户表r_user保存用户名等信息.现需要给每个用户设置工作基地,一个用户可以有多个工作基地,多个用户也可以有一个工作基地,即多对多关系.(外键,若有两个表A,B,C是A的主键,而B中也有C ...

  9. Netbeans取消CTRL+\才能代码提示的方法

    更好的方法: ------------------------------------------------------------ 边打字边按CTRL+\进行代码提示的方法我TM也是醉了 简而言之 ...

  10. flume A simple example

    http://flume.apache.org/FlumeUserGuide.html A simple example