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. Kubernetes使用prometheus+grafana做一个简单的监控方案

    前言 本文介绍在k8s集群中使用node-exporter.prometheus.grafana对集群进行监控.其实现原理有点类似ELK.EFK组合.node-exporter组件负责收集节点上的me ...

  2. C-C Primer Plus阅读笔记

    常用头: stdio.h string.h inttypes.h limits.h float.h 1.打印short.long.long long和unsigned #include <std ...

  3. git 命令使用速查手册( 个人版)

    1. 克隆远程库 git clone   repository_address 通过 git clone 获取的git库只是远程库中的当前工作分支,如果想获取其它分支信息,可参考下面. 2. 查看远程 ...

  4. java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map

    1.错误描写叙述 java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map at servic ...

  5. chrome扩展(浏览器插件)开发实用教程

    原创文章,转载请注明出处. 作者:简体字丶冯; QQ:564372931 1.Chrome能搞这些事情 (1)     操作浏览器中打开的页面DOM 这能做什么哪?譬如说你想修改页面DOM(DOM是什 ...

  6. 几段表单处理的JQuery代码(转)

    1 只接受数字输入 $("#uAge").keydown(function(event) { // 允许退格和删除键 if ( event.keyCode == 46 || eve ...

  7. ASP.NET MVC Razor 输出没有编码的HTML字符串

    Razor引擎之前要输出一段没有编码的字符串,只要@加变量名就可以了,Razor却不能这样,感觉是有点麻烦. 在Razor Beta 2以前的版本可以: @(new HtmlString(mystri ...

  8. Windows GDI 映射模式(出自:Windows程序设计第5版-珍藏版)

    GDI映射模式(mapping mode):和映射模式紧密相关的还有4个其它的设备环境属性:1.窗口原点(window origin)2.视口原点(viewport origin)3.窗口范围(win ...

  9. sapjco3 开发与部署环境设置

    windows 环境设置 1.sapjco3.dll 需要与 sapjco3.jar 在同一目录 2.设置系统环境变量,将sapjco3所在目录加入系统环境变量 3.根据自己的操作系统版本选择对应的s ...

  10. Lua顺序 执行顺序

    1.4.2. Lua顺序 Nginx下Lua处理阶段与使用范围: init_by_lua http set_by_lua server, server if, location, location i ...