[HDU4669]Mutiples on a circle

K
n<=5e4,K<=200,a[i][1,1000]
((((((
K200
2np[i]a[1...i]K
ip[i]p[j1]10ij%K=0
ip[j]10K
cnt[i]p[j1]10ij%K=ij
cntcnt1[i10%K]=cnt[i]
inin
i=n[1,n][n+1,n+n]
O(2nk)
T10i%K

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <cstdlib>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ull unsigned long long
#define null NULL
#define PI M_PI
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define scln(x) scanf("%d\n", &x)
#define sc64ln(x) scanf("%I64d\n", &x)
#define pr(x) printf("%d", x)
#define prs(x) printf("x")
#define prln(x) printf("%d\n", x)
#define prsp(x) printf("%d ", x)
#define pr64(x) printf("%I64d", x)
#define pr64ln(x) printf("%I64d\n", x)
#define pr64sp(x) printf("%I64d ", x)
#define rep(i,n) for (int i = 1;i <= (n); ++i)
#define repr(i,n) for (int i = (n);i > 0; --i)
#define repab(i,a,b) for (int i = a;i <= b; ++i)
#define Rep(i,n) for (int i = 0;i < (n); ++i)
#define Repr(i,n) for (int i = (n)-1;i >= 0; --i)
#define Repab(i,a,b) for (int i = a;i < b; ++i)
#define fi first
#define se second
#define SET(__set, val) memset(__set, val, sizeof __set)

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pll;

template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}
template<class T> T power(T a, T b){T res(1);while(b){if(b&1)res=res*a;a=a*a;b>>=1;}return res;}
template<class T> T powerM(T a, T b, T mod){T res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

const int infi = 2147483647;
const ll infl = 9223372036854775807;

#define N 111000
#define M 200

int n, m, k, T;
int cnt[2][M],a[N],p[N];
int getlen(int x){
    int res=0;
    while(x){
        res++,x/=10;
    }
    return res;
}
int shi[N<<1];
int main(){
    while (~sc(n)){
        sc(k);
        shi[0] = 1;
        rep(i,4*n)
            shi[i] = shi[i-1]*10%k;
        rep(i,n){
            sc(a[i]);
            a[i+n]=a[i];
        }
        SET(cnt,0);
        int flag=0;
        m = 0;
        ll ans = 0, ans1 = 0;
        cnt[flag][0] = 1;
        rep(i,n*2){
            int len = getlen(a[i]);
            if(i<=n)m+=len;
            p[i] = (p[i-1]*shi[len]+a[i])%k;
            SET(cnt[flag^1],0);
            Rep(j,k)
                if(cnt[flag][j]>0)
                    cnt[flag^1][j*shi[len]%k] += cnt[flag][j];
            flag ^= 1;
            ans += cnt[flag][p[i]];
            cnt[flag][p[i]]++;
            if(i>=n){
                int now = shi[m]*p[i-n]%k;
                cnt[flag][now]--;
            }
            if(i==n)ans1 = ans;
        }
        pr64ln(ans-ans1);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值