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. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-报错0X4655,18005错误怎么办

    首先确认驱动器没有报错(如果驱动器报错,请先解决绝对值编码器的清除多圈数据问题) 报错一般上使能就会报错,没法测试运转,而且不管是用贝福自带的NC功能还是自己写的都会一样的效果   请删除在贝福的Et ...

  2. C#秘密武器之反射——替换反射

    反射虽然有时很有必要,但是应用反射的代码大多“复杂难懂”.“性能不高”,因此我们可以找寻在一些场景下替换反射的方法.此处也只是一些栗子,更多巧妙的应用还是自己以后亲自查查~ 先来看看一个使用普通反射完 ...

  3. 【 D3.js 入门系列 --- 5 】 怎样加入坐标轴

    本人的个人博客为: www.ourd3js.com csdn博客为: blog.csdn.net/lzhlzz 转载请注明出处.谢谢.      第3节中做了一个图标.但没有为它加入一个对应的坐标轴. ...

  4. C语言-十进制转换为二进制函数

    char * itobs(int num, char * str) { int i; * sizeof(int); ; i >= ; i--, num >>= ) { str[i] ...

  5. CentOS 7中mariadb编译安装教程systemctl启动

    mariadb做为mysql的替代品 现在centos的新版本yum包已换成mariadb 跟上篇一样只是启动方式改为systemd 安装一些库 yum install gcc gcc-c++ wge ...

  6. eclipse代码凝视之模板xml

    曾经在eclipse中配置凝视的时候,都是各自在自己电脑上配置凝视,每一个同事风格不一样,并且配置繁琐.假设新来的同事忘了提醒,可能就没有配置凝视了.所以我就把类.方法的凝视写成xml文件.然后将配置 ...

  7. Servlet3.0: 简介AsyncContext

    每个请求来到Web容器,Web容器会为其分配一条执行绪来专门负责该请求,直到回应完成前,该执行绪都不会被释放回容器. 执行绪会耗用系统资源,若有些请求需要长时间处理(例如长时间运算.等待某个资源),就 ...

  8. sigaction()之sa_mask

    man文档描述: sa_mask gives a mask of signals which should be blocked during execution of the signal hand ...

  9. github使用和推送到服务器端。。。

    Alan Alan -- :: 第二节:创建一个仓库(Create A Repo Repositories) 直接在自己的登录后进入 github.com 首页就可以看到, 下面一栏有四步.用来创建 ...

  10. FreeBSD将SHELL从csh换成bash并支持中文显示

    刚准备在FreeBSD下学习Shell,结果发现怎么好多命令都没有,比如declare.后来发现连bash都没有,好像bash用的多一些吧,于是就准备将csh换成bash. 由于没有bash,所以先得 ...