CodeForces D. Concatenated Multiples
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.
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).
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.
6 11
45 1 10 12 11 7
7
4 2
2 78 4 10
12
5 2
3 7 19 3 3
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的更多相关文章
- 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 ...
- D. Concatenated Multiples 解析(思維)
Codeforce 1029 D. Concatenated Multiples 解析(思維) 今天我們來看看CF1029D 題目連結 題目 給你一個序列\(a\)和一個數字\(k\),求有幾種ind ...
- Codeforces Round #506 D. Concatenated Multiples题解
一.传送门 http://codeforces.com/contest/1029/problem/D 二.题意 给你$N$个数字$a_1,a_2,\cdots,a_n$,一个$K$,求所有$i \ne ...
- Codeforces | CF1029D 【Concatenated Multiples】
\(qwq\)昨天晚上\(Div.3\)过了这道题...早上交了\(1A\)...看在\(CF\)上\(hack\)的情况并不乐观而且也没人来交这题的份上...我决定发一篇题解帮\((zhuang)\ ...
- Codeforces Round #506 (Div. 3) - D. Concatenated Multiples(思维拼接求是否为k的倍数)
题意 给你N个数字和一个K,问一共有几种拼接数字的方式使得到的数字是K的倍数,拼接:“234”和“123”拼接得到“234123” 分析: N <= 2e5,简单的暴力O(N^2)枚举肯定超时 ...
- Codeforces Round #506 (Div. 3) 1029 D. Concatenated Multiples
题意: 给定n个数字,和一个模数k,从中选出两个数,直接拼接,问拼接成的数字是k的倍数的组合有多少个. 思路: 对于a,b两个数,假定len = length of (b),那么a,b满足条件就是a ...
- D. Concatenated Multiples(离线处理)
思路:直接离线处理出每个ai 的10倍, 100倍, 1000倍的mod k 后的数值的个数,使用map<int,int >ss[12]存储, ss[x][y]表示 (ai*10x)%k= ...
- Codeforces Round #506 (Div. 3) 题解
Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...
- Codeforces Round #506 (Div. 3) D-F
Codeforces Round #506 (Div. 3) (中等难度) 自己的做题速度大概只尝试了D题,不过TLE D. Concatenated Multiples 题意 数组a[],长度n,给 ...
随机推荐
- Yarn下分片和分块源代码分析
public class FileSplit extends InputSplit implements Writable { private Path file; private long star ...
- JavaEE权限管理系统的搭建(二)--------聚合工程项目的创建和依赖关系
本项目是一个聚合工程,所以要先搭建一个聚合工程的框架 搭建完成的项目结构图如下: 首先创建父项目:pom类型 子模块:web层的搭建,war类型 把这个两个目录标记为对应的类型 其他子模块:和serv ...
- File类,递归
File类 File文件和目录路径名的抽象表示形式.即,Java中把文件或者目录(文件夹)都封装成File对象. File类包含 路径 path E:\... 目录 direct ...
- NoClassDefFoundError: com/ibatis/sqlmap/engine/transaction/external/ExternalTransactionConfig处理
根据老系统拷贝maven依赖新搭建了一个项目,启动抛异常如下: Caused by: java.lang.NoClassDefFoundError: com/ibatis/sqlmap/engine/ ...
- 面试-Spring理解
转自http://hui.sohu.com/infonews/article/6331404387079946240 spring呢,是pivotal公司维护的一系列开源工具的总称,最为人所知的是sp ...
- 顺序语句:GOTO和NULL语句
一 标号和GOTO 1 语法: PL/SQL中GOTO语句是无条件跳转到指定的标号去的意思.语法如下: GOTO label;......<<label>> /*标号是用< ...
- BZOJ3671: [Noi2014]随机数生成器(贪心)
Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 2098 Solved: 946[Submit][Status][Discuss] Descripti ...
- mybatis两级缓存原理剖析
https://blog.csdn.net/zhurhyme/article/details/81064108 对于mybatis的缓存认识一直有一个误区,所以今天写一篇文章帮自己订正一下.mybat ...
- Shell学习——数值运算
在Bash shell中,可以利用let.(( )).[]执行基本的算术操作,在高级操作时,使用expr和bc两个工具1.let[root@client02 ~]# no1=4[root@client ...
- ethereum(以太坊)(一)
从这周开始,开始学习以太坊开发--solidity,开始决定往区块链方向发展,毕竟区块链技术应用广泛.一开始接触solidity开发语言不太习惯,毕竟一直在学习python语法,有很多都不能接受.有难 ...