zoukankan      html  css  js  c++  java
  • [CERC2015]Digit Division

    题目描述

    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 10^9 +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.

    输入输出格式

    输入格式:

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

    输出格式:

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

    输入输出样例

    输入样例#1: 
    4 2
    1246
    输出样例#1: 
    4
    输入样例#2: 
    4 7
    2015
    输出样例#2: 
    0

    说明

    Central Europe Regional Contest 2015 Problem D

    我们发现分出来的每段的末尾i 的前缀数字 s[i] 都必须是 m的倍数, 否则中间肯定有一段%m!=0(想一想为什么),然后这就是个SB题了233

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int ha=1000000007;
    int n,m,T,num;
    char ch;
    
    inline int add(int x,int y){
    	x+=y;
    	return x>=ha?x-ha:x;
    }
    
    inline int C(int y){
    	int an=1,x=2;
    	for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
    	return an;
    }
    
    int main(){
    	scanf("%d%d",&n,&m);
    	const int M=m;
    	for(int i=1;i<=n;i++){
    		ch=getchar();
    		while(!isdigit(ch)) ch=getchar();
    		num=((num*10)+ch-'0')%M;
    		if(!num) T++;
    	}
        if(num) puts("0");
    	else printf("%d
    ",C(T-1));
    	return 0;
    }
    

      

  • 相关阅读:
    【解压缩命令】 -费元星
    【虚拟机取得该虚拟机的所有权失败】--费元星
    solr 常见的问题整理 -费元星
    oracle 建立一个视图,然后授权其他用户访问
    虚拟机安装win7 64位-完美解决-费元星
    solr 学习
    CentOS安装JDK1.7
    Nginx+Tomcat多站点访问默认主页问题-狒狒完美解决-Q9715234
    pip 安装时提示uvloop/loop.c:20:10: fatal error: Python.h解决
    MySQL锁总结
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8678330.html
Copyright © 2011-2022 走看看