题目传送门
代码:
#include<bits/stdc++.h>
using namespace std;typedef long long LL;
const int maxn=200000+10;map<int,int> M[11];
int ans[maxn];
short bit[maxn];int main(){int n,k,tmp;scanf("%d%d",&n,&k);for(int i=1;i<=n;i++){scanf("%d",&ans[i]);tmp=ans[i];while(tmp) tmp/=10,bit[i]++;ans[i]%=k;M[bit[i]][ans[i]]++;}LL num=0,mul;for(int i=1;i<=n;i++){M[bit[i]][ans[i]]--;mul=10;for(int j=1;j<11;j++){tmp=k-(mul%k*ans[i])%k;if(tmp==k) tmp=0;auto it=M[j].find(tmp);if(it!=M[j].end()) num+=it->second;mul*=10;}M[bit[i]][ans[i]]++;}printf("%lld\n",num);return 0;
}