题目

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的更多相关文章

  1. 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 ...

  2. Codeforces Round #464 (Div. 2) D题【最小生成树】

    Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her b ...

  3. 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 ...

  4. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 【VS开发】字符,字节和编码

    字符,字节和编码 [原创文章,转载请保留或注明出处:http://www.regexlab.com/zh/encoding.htm] 级别:中级 摘要:本文介绍了字符与编码的发展过程,相关概念的正确理 ...

  2. 关于deepin装机的一些经验总结

    最近win10用的有一点腻,虚拟机很久之前就装上了deepin,乌班图,红帽等隶属于Linux一些操作系统,但是终究还是虚拟机所以还是想在真机上试试,所以照着deepin网上的流程装好了deepin并 ...

  3. analyticdb(ADB) group by 用法小结

    虽说analyticdb(ADB)是支持mysql协议的,但有些具体细节用法是有些区别. 1.group by 字段 mysql group by select id,title,describe w ...

  4. java 统计素数个数问题

    题目:判断101-200之间有多少个素数,并输出所有素数. 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数. package Study ...

  5. (5.10)mysql高可用系列——percona-toolkit工具下的pt-table-checksum 在线验证主从一致性【续写中】

    关键词:percona-toolkit 工具包中包含 pt-table-checksum工具,在线验证主从一致性 [1]percona-toolkit 工具包 [1.1]percona-toolkit ...

  6. sublime text3 注册码 (Version 3.0)

    -– BEGIN LICENSE -– TwitterInc 200 User License EA7E-890007 1D77F72E 390CDD93 4DCBA022 FAF60790 61AA ...

  7. P4942小凯的数字

    给定一个序列,如12345 56789 1011121314等,输出对其取余9的结果. 那么我们需要明白一个定理,一个序列对一个数的取余结果等于它各位之和取余那个数的结果.证明似乎是这样∑i=0n​a ...

  8. %300为0的个数(牛客第四场)-- number

    题意: 给你一串数,问你如题. 思路: 我不是这样的作法,从后往前,先取00,再算%3==0的个数,往前推的时候有递推关系: #define IOS ios_base::sync_with_stdio ...

  9. 2019中山纪念中学夏令营-Day2[JZOJ]

    博客的开始,先聊聊代码实现: 每次比赛以后,要有归纳错误的习惯. 错误小结: 1.读入:scanf(“%c”)会读入回车和空格,但cin不会. 2.对于二维数组的输入,不能把m,n搞混了,会引起严重的 ...

  10. C# 如何判断指定文件是否正被其它程序使用

    C# 如何判断指定文件是否正被其它程序使用 起因:项目中发现在操作文件时,系统经常抛出异常,表示文件正被其它程序占用. 需求:为了事先判断,以确认指定的文件是否正被其它程序使用,需要方法进行判断. 思 ...