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 ...
随机推荐
- 【VS开发】内存泄漏相关问题
之所以撰写这篇文章是因为前段时间花费了很大的精力在已经成熟的代码上再去处理memory leak问题.写此的目的是希望我们应该养成良好的编码习惯,尽可能的避免这样的问题,因为当你对着一大片的代码再去处 ...
- Mybatis(三) 动态SQL
if + where 用法 1. if 元素来实现多条件查询 1.1 UserMapper.xml配置文件 <!--查询用户列表 (if)--> <select id="g ...
- 一些通用的js工具类,添加自定义插件
common_t.js /** * 通用工具组件 对原有的工具进行封装,自定义某方法统一处理<br> * ^_^ * * Author: em.D * Date: 2016-05-17 * ...
- vue项目中微信jssdk在ios签名失败
一.问题描述 1. vue项目中微信jssdk签名时,在安卓和ios是有差异的,签名时使用的url=window.location.href.split('#')[0],此时在安卓没问题,在ios会导 ...
- idea 修改pom文件jdk版本回退问题解决
在Java开发是我们大多都使用集成开发环境,像idea和eclipse用的都比较多,在使用idea maven构建项目时,在修改pom.xml文件时,我们的项目jdk版本都会回退,还得每次去设置中修改 ...
- python词云生成-wordcloud库
python词云生成-wordcloud库 全文转载于'https://www.cnblogs.com/nickchen121/p/11208274.html#autoid-0-0-0' 一.word ...
- mysql设计与优化以及数据库表设计与表开发规范
一.设计问题? 1.主键是用自增还是UUID ? Innodb 中的主键是聚簇索引. 如果主键是自增的,那么每次插入新的记录,记录就会顺序添加到当前索引节点的后续位置,当一页写满,就会自动开辟一个新的 ...
- TensorFlow入门——MNIST初探
import tensorflow.examples.tutorials.mnist.input_data as input_data import tensorflow as tf mnist = ...
- Shell编程备份数据库
案例: 在/usr/sbin/建立Shell文件 备份后查看目录: 然后进行crontab任务调度: #每天凌晨两点十分调度一次 * * * /usr/sbin/mysql_db.sh
- 10、LNMP架构
1LNMP架构概述 1.1.什么是LNMP LNMP 是一套技术的组合,L = Linux,N = Nginx,M~ = MySQL,P~ = PHP 1.2.LNMP架构是如何工作的 首先Ngin ...