和一个数位dp里的取模方式很像
// A[i] * 10^len(j) + A[j] == 0(mod k)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 100005;
LL n, k, a[N], s[N][11]; // x*10^j % k == i 个数
LL mod(LL x, LL p){
return (x % p + p) % p;
}
int main(){
scanf("%lld%lld", &n, &k);
for(int i = 0; i < n; i ++ )
scanf("%lld", &a[i]);
for(int i = 0; i < n; i ++ ){
LL t = a[i] % k;
for(int j = 0; j < 11; j ++ ){
s[t][j] ++;
t = t * 10 % k;
}
}
LL res = 0;
for(int i = 0; i < n; i ++ ){
int len = log10(a[i]) + 1;
LL t = a[i] % k;
LL x = mod(-t, k);
res += s[x][len];
while(len -- ) t = t * 10 % k;
if(t == x) res --;
}
cout << res;
return 0;
}