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. 激活SQLPrompt7.4及以上版本

    SQLPrompt是个很好的sql server提示工具,SQL-SERVER2016只能使用SQLPrompt7.x 以上版本,用激活工具激活后没多久就会检测到激活码不可用.所以感觉是不是有个服务在 ...

  2. P3366 最小生成树【模板+Kruscal讲解】

    此题数组大小非常重要 算法过程: 现将全部边按照权值(由小到大)排序. 按顺序(同上)考虑每条边,只要这条边和之前已选择的边不构成圈,就保留这条边,否则放弃这条边. 具体算法 成功选择(n-1)条边后 ...

  3. Eclipse编写JavaFX环境配置

    配置eclipse用于写JavaFX:1.确定JRE中有jfxrt.jar---jdk82.选中项目-->属性-->Java Build Path3.Libraries-->jre包 ...

  4. Java高并发之线程基本操作

    结合上一篇同步异步,这篇理解线程操作. 1.新建线程.不止thread和runnable,Callable和Future了解一下 package com.thread; import java.tex ...

  5. python爬虫:利用正则表达式爬取豆瓣读书首页的book

    1.问题描述: 爬取豆瓣读书首页的图书的名称.链接.作者.出版日期,并将爬取的数据存储到Excel表格Douban_I.xlsx中 2.思路分析: 发送请求--获取数据--解析数据--存储数据 1.目 ...

  6. ubuntu安装wine 和sourceinsght

    ubuntu安装wine: 1.sudo apt-get update 2.sudo apt-get install wine 安装完成后会在当前用户目录的的家目录下生成.wine目录,该目录就是wi ...

  7. iOS常用控件-UIScrollView

    一. 常见属性 @property (nonatomic) CGPoint contentOffset;                      //记录UIScrollView滚动的位置 @pro ...

  8. poj 2579 中位数问题 查找第K大的值

    题意:对列数X计算∣Xi – Xj∣组成新数列的中位数. 思路:双重二分搜索 对x排序 如果某数大于 mid+xi 说明在mid后面,这些数的个数小于 n/2 的话说明这个中位数 mid 太大 反之太 ...

  9. python-12正则表达式

    import re #re.search方法 re.search 扫描整个字符串并返回第一个成功的匹配. re.match('com', 'www.runoob.com') #匹配失败 None re ...

  10. 笔记-python-lib-contextlib

    笔记-python-lib-contextlib 1.      contextlib with 语句很好用,但不想每次都写__enter_-和__exit__方法: py标准库也为此提供了工具模块c ...