To become the king of Codeforces, Kuroni has to solve the following problem.

He is given n numbers a1,a2,…,an. Help Kuroni to calculate ∏1≤i<j≤n|ai−aj|. As result can be very big, output it modulo m.

If you are not familiar with short notation, ∏1≤i<j≤n|ai−aj| is equal to |a1−a2|⋅|a1−a3|⋅ … ⋅|a1−an|⋅|a2−a3|⋅|a2−a4|⋅ … ⋅|a2−an|⋅ … ⋅|an−1−an|. In other words, this is the product of |ai−aj| for all 1≤i<j≤n.

Input
The first line contains two integers n, m (2≤n≤2⋅105, 1≤m≤1000) — number of numbers and modulo.

The second line contains n integers a1,a2,…,an (0≤ai≤109).

Output
Output the single number — ∏1≤i<j≤n|ai−aj|modm.

Examples
inputCopy
2 10
8 5
outputCopy
3
inputCopy
3 12
1 4 5
outputCopy
0
inputCopy
3 7
1 4 9
outputCopy
1
Note
In the first sample, |8−5|=3≡3mod10.

In the second sample, |1−4|⋅|1−5|⋅|4−5|=3⋅4⋅1=12≡0mod12.

In the third sample, |1−4|⋅|1−9|⋅|4−9|=3⋅8⋅5=120≡1mod7.

这就是个鸽笼原理,m<=1000

#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{char ch = getchar();x = 0;t f = 1;while (ch < '0' || ch > '9')f = (ch == '-' ? -1 : f), ch = getchar();while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar();x *= f;
}#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 200005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
int a;
int b[1005], flag;
vector<pair<int, int>> c;
int main()
{int n, m;read(n), read(m);for (int i = 0; i < n; i++){read(a);int mo = a % m;b[mo]++;c.push_back(make_pair(mo, a));if (b[mo] >= 2)flag = 1;// cout << mo << endl;}if (flag){puts("0");return 0;}int ans = 1;for (int i = 0; i < c.size(); i++){for (int j = i + 1; j < c.size(); j++){if (c[i].second > c[j].second){ans *= (c[i].first - c[j].first + m);}else{ans *= (-c[i].first + c[j].first + m);}ans %= m;}}cout << ans << endl;
}

Codeforce-Ozon Tech Challenge 2020-C. Kuroni and Impossible Calculation(鸽笼原理)相关推荐

  1. Ozon Tech Challenge 2020 (Div.1 + Div.2) F. Kuroni and the Punishment 随机化

    传送门 文章目录 题意: 思路: 题意: 给你nnn个数,每次操作可以选择将某个数+1,−1+1,-1+1,−1,求最少进行多少次操作使得所有数都为正数且gcd>1gcd>1gcd> ...

  2. Ozon Tech Challenge 2020 (Div.1 + Div.2) E.Kuroni and the Score Distribution 构造

    传送门 文章目录 题意: 思路: 题意: 思路: 不难想到,长度为nnn的数组最多的满足条件的三元组序列是1,2,3....,n1,2,3....,n1,2,3....,n,对于每一个位置贡献为i−1 ...

  3. Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated) D. Kuroni and the Celebration 交互 + 思维

    传送门 文章目录 题意: 思路: 题意: 给你一颗树,每次可以询问两个点的lcalcalca,询问次数不能超过⌊n2⌋\left \lfloor \frac{n}{2} \right \rfloor⌊ ...

  4. Ozon Tech Challenge 2020 (Div.1 + Div.2) C. Kuroni and Impossible Calcul 抽屉原理

    传送门 文章目录 题意: 思路: 题意: 给你一个数组ana_nan​,求∏1≤i<j≤n∣aj−ai∣modm\begin{matrix} \prod_{1\le i<j\le n} | ...

  5. Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated, T-shirts + prizes!)

    Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated, T-shirts + prizes!) 题号 题目 知识点 A Kuroni and the Gifts ...

  6. Kuroni and Impossible Calculation CodeForces - 1305C(鸽巢原理)

    To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a ...

  7. CodeForces - 1305C Kuroni and Impossible Calculation(鸽巢原理)

    题目链接:点击查看 题目大意:给出 n 个数,输出两两绝对值之差相乘对 m 取模后的答案 题目分析:读完题后乍一看感觉 n 很大,不能 n * n 暴力解决,但是发现 m 非常小,因为有了 m 的限制 ...

  8. 2020最后一天 || 时间相关单光子计数技术的原理和优点

    相关博客: 2020最后一天 || 时间相关单光子计数技术的原理和优点 2020最后一天 || 常用光子计数检测器分类与原理 2020最后一天 || 时间相关单光子计数器(TCSPC)的定时分辨率(T ...

  9. Codechef June Challenge 2020 简要题解

    这次题目比较简单. The Tom and Jerry Game! 略 Operations on a Tuple 略 The Delicious Cake 略 Convenient Airports ...

最新文章

  1. 理解透彻--802.1d,802.1w,802.1s与802.1q
  2. Java编程时部分快捷键
  3. HandlerThread原理与应用
  4. 封装fetch的使用(包含超时处理)
  5. 获取授时时间_gps时间同步服务器在通信行业的解决方案
  6. kotlin学习之基础(一)
  7. python eel 多线程_Python 基础
  8. LeetCode 6060. 找到最接近 0 的数字
  9. 每日小记2017.2.22
  10. tcp长连接java_JAVA TCP长连接
  11. WebRAY创业启示录:从小公司到隐形的巨人
  12. ACM PKU 题目分类(完整整理版本)
  13. c语言开发gc,GC的基本原理
  14. 2021 知来者之可追
  15. 用插件MAVEN-SUREFIRE-REPORT-PLUGIN生成HTML格式测试报告
  16. 电脑锁屏卡死以及任务栏卡死的解决办法
  17. 【RPA学习天地:版本解读】艺赛旗iS-RPA2021.2版本亮点
  18. Vue Language Features (Volar) 会引起ts报错
  19. python--字典、列表
  20. 可信云最高级认证 百度飞桨企业版BML就是这么飒!

热门文章

  1. mysql explain 索引_MySql中Explain详解与索引最佳实践
  2. 计算机网络 鲁士文,《在职研究生计算机网络课程统考复习指南》鲁士文 编_孔网...
  3. java判断读到末尾_Flink实战:自定义KafkaDeserializationSchema(Java/Scala)
  4. python 控件叠加_Python3 tkinter基础 Checkbutton anchor for生成多个控件并西对齐
  5. 前端小白也能快速学会的博客园博客美化全攻略
  6. NSURLSessionDataTask与NSOperationQueue实现多文件断点下载(任意时刻终止进程,重启应用,自动重启下载)...
  7. 阿里安全猎户座实验室(Alibaba Orion Security Lab)简介
  8. idea下一次Jar包依赖问题的解决过程
  9. Azure恢复服务-DPM联机备份SQL数据库
  10. Windows7 Credential Manage