Codeforces Round #395 Div.1 C pacifist【JZOJ5449】Pacifist
题目
papyrus 喜欢谜题... 来解一道如何?
在你面前有一个被加密了的数组,其原数组是一个等差序列,你面前的则是将原数组中的所有数字都对m 取模再打乱后而得到的新数组
papyrus 给你出的谜题就是还原出原等差序列
保证数据有解,而且因为papyrus 喜欢质数,所以他给你出的谜题中的m 一定是质数
分析
将a排序,当a[1]不是末项时,a[i]-a[1]一定有一个为公差
枚举公差d,
我们就可以通过等差数列和来求出首项a1,
我们通过a1和d来求出对应的等差数列平方和,na1²+n(n-1)d+n(n-1)(2n-1)d²
判断是否符合。
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <queue>
using namespace std;
const int maxlongint=2147483647;
const int N=100005;
long long mo,a[N],sum,ny,n,su,ny1;
long long mi(long long x,int y)
{
long long sum=1;
for(;y;)
{
if(y&1) sum=sum*x%mo;
x=x*x%mo;
y>>=1;
}
return sum;
}
int main()
{
freopen("pacifist.in","r",stdin);
//freopen("pacifist.out","w",stdout);
scanf("%lld%lld",&mo,&n);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]),su=(su+a[i])%mo,sum=(sum+a[i]*a[i]%mo)%mo;
sort(a+1,a+1+n);
if(n==mo)
{
printf("0 1");
return 0;
}
ny=mi(6,mo-2);
ny1=mi(n,mo-2);
for(int i=2;i<=n;i++)
{
long long d=(a[i]-a[1])%mo;
if(!d) continue;
long long a1=(2*su*ny1%mo-d*(n-1)%mo+mo)%mo*mi(2,mo-2)%mo;
if((n*a1%mo*a1%mo+n*(n-1)%mo*(2*n-1)%mo*d%mo*d%mo*ny%mo+n*(n-1)%mo*d%mo*a1%mo)%mo==sum)
{
printf("%lld %lld",a1,d);
return 0;
}
}
}
Codeforces Round #395 Div.1 C pacifist【JZOJ5449】Pacifist的更多相关文章
- Codeforces Round #446 (Div. 2) A. Greed【模拟】
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #464 (Div. 2) D题【最小生成树】
Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her b ...
- Codeforces Round #395 (Div. 2) A. Taymyr is calling you【数论/最小公倍数】
A. Taymyr is calling you time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Round #451 (Div. 2) A. Rounding【分类讨论/易错】
A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #164 (Div. 2) A. Games【暴力/模拟/每个球队分主场和客场,所有球队两两之间进行一场比赛,要求双方球服颜色不能相同】
A. Games time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #446 (Div. 2) B. Wrath【模拟/贪心】
B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #447 (Div. 2) A. QAQ【三重暴力枚举】
A. QAQ time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Codeforces Round #271 (Div. 2) D Flowers【计数dp】
D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- NoSQL数据库简介与产生
关系型数据库所存在“问题” >利用ACID原则(原子性,一致性,隔离性,持久性)保证数据完整性: >行列的规范化存储: >预定义结构: >存储数据量“小”: >结构化查询 ...
- CSP-J 2019 T3 纪念品
\(\mathfrak{a}\).反思: 通过这道题成功发现自己的背包还是很差\(w\): 可能这是我\(gu\)了好久好久博客的报应叭 就在做这个题的时候,自己连背包\(dp\)的思想都忘了 背包可 ...
- redis在php中实际应用-hash
Redis hash 是一个string类型的field和value的映射表,hash特别适合用于存储对象. 目录: 1.批量赋值:hmset,hmget,hgetall 可用于存储一条条数据,即一个 ...
- Docker学习1
命名空间(Namesaoces):Linux内核提供的一种对进程资源隔离的机制,例如网络.进程.挂载点等资源. 控制组(CGroups):Linux内核提供的一种限制进程资源的机制:例如CPU.内存等 ...
- 从入门到自闭之Python高阶函数
高阶函数:内部帮忙做了一个for循环 filter:筛选过滤 语法: filter(function,iterable) function: 1.指定过滤规则(函数的内存地址) 2.用来筛选的函数,在 ...
- JAVA基础:Java中equals和==的区别
java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,double,boolean 他们之间的比较,应用双等号( ...
- java -cp 执行jar包里的某个类
当我们需要测试某个功能时,需要在linux环境下执行某个类的main方法来测试 可以使用java -cp xxx.jar com.MyClass来执行某个类 java -cp test.jar:lib ...
- vue运行碰到的问题
Expected indentation of 0 spaces but found 2 解决方案: 文件中加入"indent": ["off", 2]就可以了 ...
- 磁盘(disk)结构
- angular项目中ts的配置编译tsconfig.json
{ "compilerOptions": { /* 基本选项 */ "target": "es5", // 指定 ECMAScript 目标 ...