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;
}

  

CodeForces D. Concatenated Multiples的更多相关文章

  1. Codeforces Round #506 (Div. 3) D. Concatenated Multiples

    D. Concatenated Multiples You are given an array aa, consisting of nn positive integers. Let's call ...

  2. D. Concatenated Multiples 解析(思維)

    Codeforce 1029 D. Concatenated Multiples 解析(思維) 今天我們來看看CF1029D 題目連結 題目 給你一個序列\(a\)和一個數字\(k\),求有幾種ind ...

  3. Codeforces Round #506 D. Concatenated Multiples题解

    一.传送门 http://codeforces.com/contest/1029/problem/D 二.题意 给你$N$个数字$a_1,a_2,\cdots,a_n$,一个$K$,求所有$i \ne ...

  4. Codeforces | CF1029D 【Concatenated Multiples】

    \(qwq\)昨天晚上\(Div.3\)过了这道题...早上交了\(1A\)...看在\(CF\)上\(hack\)的情况并不乐观而且也没人来交这题的份上...我决定发一篇题解帮\((zhuang)\ ...

  5. Codeforces Round #506 (Div. 3) - D. Concatenated Multiples(思维拼接求是否为k的倍数)

    题意 给你N个数字和一个K,问一共有几种拼接数字的方式使得到的数字是K的倍数,拼接:“234”和“123”拼接得到“234123” 分析: N <= 2e5,简单的暴力O(N^2)枚举肯定超时 ...

  6. Codeforces Round #506 (Div. 3) 1029 D. Concatenated Multiples

    题意: 给定n个数字,和一个模数k,从中选出两个数,直接拼接,问拼接成的数字是k的倍数的组合有多少个. 思路: 对于a,b两个数,假定len = length of (b),那么a,b满足条件就是a ...

  7. D. Concatenated Multiples(离线处理)

    思路:直接离线处理出每个ai 的10倍, 100倍, 1000倍的mod k 后的数值的个数,使用map<int,int >ss[12]存储, ss[x][y]表示 (ai*10x)%k= ...

  8. Codeforces Round #506 (Div. 3) 题解

    Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...

  9. Codeforces Round #506 (Div. 3) D-F

    Codeforces Round #506 (Div. 3) (中等难度) 自己的做题速度大概只尝试了D题,不过TLE D. Concatenated Multiples 题意 数组a[],长度n,给 ...

随机推荐

  1. Entityframework对应sqlserver版本问题

    修改.edmx文件中 providermanifesttoken 的值

  2. 记一次EBS正式环境补丁安装的过程

    因菏泽能源上线需求,需要在8009上修复集团8000环境上已经修复的所有补丁程序,修复前做应用及数据库层备份,完成修复后解决并发管理器无法启动的问题.此为概述. 应用层备份 应用层的备份采用直接压缩备 ...

  3. mariadb源码编译安装及多实例

    准备文件源文件/app/mariadb-10.2.12.tar.gz cd /app/ tar xf mariadb-10.2.12.tar.gz cd  mariadb-10.2.12 mkdir ...

  4. Java对象容器总结

    泛型容器类 容器类型: ArrayList 元素类型: 有排序 String:里面存放的是对象的管理者,而不是具体的对象,所以string类型有null值 集合容器 容器类型 Set 元素类型 唯一性 ...

  5. spring-bean(xml方式DI)

    三种属性注入方式 构造函数注入 1.在Bean实体中写入构造函数(带参构造) 2. <bean id=”该bean的名称” class=”注入的bean的全路径”> <constru ...

  6. js函数的默认参数

    function f(flag, start, end, msg){ flag = flag == false ? flag : true; start = start || null; start ...

  7. rsync同步备份搭建

    Rsync 是 Unix/Linux 下的一款应用软 在平常的运维中进常要对一些数据进行备份,以防止意外的服务器故障导致不可避免的后果,tar,cp只能适应一些小范围backup,对于几T甚至几P的数 ...

  8. asp.net高并发网站解决方案【未完成版本】

    场景:假设现在是一个电商网站,今天要举办活动,有10个商品低价销售,但是会来抢购的人会特别多,最后只有十个人可以成功的买到商品   明确2个问题 1.访问量:抢票时间断用户访问量 2.并发:1秒内请求 ...

  9. 2.1 <script>元素【JavaScript高级程序设计第三版】

    向 HTML 页面中插入 JavaScript 的主要方法,就是使用<script>元素.这个元素由 Netscape 创造并在 Netscape Navigator 2 中首先实现.后来 ...

  10. 虚拟机无法ping通物理机的解决方案

    环境:Windows7下安装虚拟机,虚拟机上装有Ubuntu16.04的server版系统. 1.打开Windows防火墙,在打开或关闭Windows防火墙中 关闭Windows的防火墙. 2.禁用服 ...