题目

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. Linux C/C++基础——内存分区

    1.内存分区 在生活中,为了提高办事效率,某个单位经常会分成N个部门,每个部门职责不同,同样,为了提高 效率,我们的内存也会被分成N个区.这里我们将内存分为五个区.也有四区模型. 首先看一下一个二进制 ...

  2. python 连接SQL SERVER 并读取其数据

    1.没什么难的操作 安装  pip install pymssql import pymssql #引入pymssql模块 import pandas as pd def conn(): connec ...

  3. mysql的root密码忘了

    忘记密码:https://www.cnblogs.com/ryanzheng/p/9348723.htmlmy.cnf的[mysqld]下加:skip-grant-tables重启 mysql -ur ...

  4. Ubuntu基本操作(博主想上传图片给服务器的一些命令)

    1.将当前目录下的文件移动至指定文件夹,这里用移动至网站的根目录做示范 sudo mv bamboo.jpg /val/www/html mv bamboo.jpg /val/www/html 2.进 ...

  5. xargs、chattr命令

    一.xargs:将标准输入转化成命令行参数 用法:xargs [OPTION] ... COMMAND INITIAL-ARGS ...使用参数INITIAL-ARGS运行COMMAND,并从输入中读 ...

  6. mysql连接数据库时报2003错误怎么解决

    mysql 2003是连接错误,连不上服务器. 你目前可以如下方法:进入控制面板->服务管理(我的是管理工具),->服务,然后找到Mysql服务,右键修改属性,改为自启动,以后再重启就没有 ...

  7. solr学习笔记-入门

    solr学习笔记 1.安装前准备 solr依赖java 8 运行环境,所以我们先安装java.如果没有java环境无法启动solr服务,并且会看到如下提示: [root@localhost solr- ...

  8. jquery的ajax方法使用application/json出现400错误码的解决方案

    400说明是客户端错误,将contentType默认的application/x-www-form-urlencoded改成application/json就出现错误,说明传输的数据不是JSON. 解 ...

  9. Redis5版本集群搭建

    一.简介 1.1 Redis是什么 Redis是一个开源的,使用ANSI C 编写,高性能的Key-Value的NoSQL数据库. 1.2 Redis特点 (1)基于内存 (2)可持久化数据 (3)具 ...

  10. windows下搭建spark+python 开发环境

    有时候我们会在windows 下开发spark程序,测试程序运行情况,再部署到真实服务器中运行. 那么本文介绍如何在windows 环境中搭建简单的基于hadoop 的spark 环境. 我的wind ...