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

    题目链接:

    题目

    分析:

    首先考虑这样一个东西
    如果(t|a, t|b),那么显然(a,b)拼起来也整除(t)
    那么如果(t|a)(a,b)拼起来不整除(t),一定有(t)不整除(b)
    于是事情一下好办了起来,类似读优的方式从左到右扫描并拆位,如果当前拆下来的左半边能整除就增量答案(cnt)
    如果最后整个数不整除(t),那么拆不了,直接输出(0)
    否则答案为(2^{cnt - 1}),最后整个数那一下不算拆,所以不统计

    代码:

    #include<bits/stdc++.h>
    #define mod (1000000000 + 7)
    #define N (300000 + 10)
    #define int long long
    using namespace std;
    inline int read() {
    	int cnt = 0, f = 1; char c = getchar();
    	while (!isdigit(c)) {if (c == '-') f = -f; c = getchar();}
    	while (isdigit(c)) {cnt = (cnt << 3) + (cnt << 1) + (c ^ 48); c = getchar();}
    	return cnt * f;
    }
    int n, m;
    long long qpow(int a, int b) {
    	long long ans = 1;
    	while (b) {
    		if (b & 1) ans = (ans * (a % mod) % mod);
    		a = ((a % mod) * (a % mod)) % mod; b >>= 1;
    	}
    	return ans % mod;
    }
    char ch[N];
    int cur = 0, cnt = 0;
    signed main() {
    	n = read(), m = read();
    	scanf("%s", ch + 1);
    	for (register int i = 1; i <= n; ++i) {
    		cur = ((cur << 3) + (cur << 1) + (ch[i] ^ 48)) % m;
    		cnt += (!cur);
    	}
    	if (cur) return printf("0"), 0;
    	printf("%lld", qpow(2, cnt - 1) % mod);
    	return 0;
    }
    
  • 相关阅读:
    CNN comprehension
    Gradient Descent
    Various Optimization Algorithms For Training Neural Network
    gerrit workflow
    jenkins job配置脚本化
    Jenkins pipeline jobs隐式传参
    make words counter for image with the help of paddlehub model
    make words counter for image with the help of paddlehub model
    git push and gerrit code review
    image similarity
  • 原文地址:https://www.cnblogs.com/kma093/p/11626585.html
Copyright © 2011-2022 走看看