http://codeforces.com/contest/1029/problem/D

You are given an array aa, consisting of nn positive integers.

Let's call a concatenation of numbers xx and yy the number that is obtained by writing down numbers xx and yy one right after another without changing the order. For example, a concatenation of numbers 1212 and 34563456 is a number 123456123456.

Count the number of ordered pairs of positions (i,j)(i,j) (i≠ji≠j) in array aa such that the concatenation of aiai and ajaj is divisible by kk.

Input

The first line contains two integers nn and kk (1≤n≤2⋅1051≤n≤2⋅105, 2≤k≤1092≤k≤109).

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

Output

Print a single integer — the number of ordered pairs of positions (i,j)(i,j) (i≠ji≠j) in array aa such that the concatenation of aiai and ajaj is divisible by kk.

Examples
input

Copy
6 11
45 1 10 12 11 7
output

Copy
7
input

Copy
4 2
2 78 4 10
output

Copy
12
input

Copy
5 2
3 7 19 3 3
output

Copy
0

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 2e5 + 10;
int N, K;
int num[maxn];
map<long long, long long> mp[15]; int main() {
scanf("%d%d", &N, &K);
for(int i = 1; i <= N; i ++) {
scanf("%d", &num[i]);
long long a = num[i];
for(int j = 1; j <= 10; j ++) {
a *= 10;
a %= K;
mp[j][a] ++;
}
}
long long cnt = 0;
for(int i = 1; i <= N; i ++) {
int t = num[i] % K;
int len = log10(num[i]) + 1;
cnt += mp[len][(K - t) % K];
long long x = 1;
for(int j = 1; j <= len; j ++)
x = (x * 10) % K;
if(((num[i] * x) % K + num[i] % K) % K == 0)
cnt --;
}
printf("%I64d\n", cnt);
return 0;
}

  

最新文章

  1. *HDU1455 DFS剪枝
  2. linux系统:rm-rf执行以后,怎么办?我来教你恢复文件。
  3. 检测MYSQL不同步发邮件通知的脚本
  4. Objective-C 学习笔记(Day 1)
  5. asp.net中Get请求和Post请求
  6. DNS解析原理
  7. KEIL的混合编程操作
  8. oracle 解锁scott账户
  9. 转:Redis使用认证密码登录
  10. [51nod1457]小K vs. 竹子
  11. python3 实例方法、类方法和静态方法
  12. 第一行代码 3-2-2 软件也要拼脸蛋-UI界面-更强大的滚动条- 卡片
  13. Linux命令(十)打包压缩、软件安装
  14. Spark Hadoop Free 安装遇到的问题
  15. for和foreach的区别
  16. go语言中make和new的区别
  17. Backing Up and Restoring HBase Data
  18. 20155238 2016-2017-2 《Java程序设计》第二周学习总结
  19. Ext,合计保留两位小数
  20. [BZOJ2120]数颜色(莫队算法)

热门文章

  1. 顺序语句:GOTO和NULL语句
  2. socket上传nsdictionary的json数据异常
  3. 服务器操作nginx相关操作命令
  4. JavaScript中并非一切皆对象
  5. Win10下安装zookeeper
  6. 远程桌面连接失败,提示CredSSP加密Oracel修正问题解决
  7. 利用sysbench进行MySQL OLTP基准测试
  8. Linux系统崩溃,数据迁移
  9. Delphi7卸载indy9,安装indy10步骤
  10. 细说 unicode 、utf-8 、utf-16、ascii 、gbk 、gb2312