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 ...
随机推荐
- centos 6.5安装erlang和RabbitMQ
一.安装erlang 1.下载erlang源码 git clone https://github.com/erlang/otp.git 2.编译并安装erlang cd otp ./otp_build ...
- filter_var()函数
我们使用 payload :?url=javascript://comment%250aalert(1) ,可以执行 alert 函数: 实际上,这里的 // 在JavaScript中表示单行注释,所 ...
- 贡献python prim多源最短路搜索算法 numba加速方法的demo和总结
1.测试两个算法 #coding:utf-8 import time import numba import numpy as np ''' 使用numba加速总结, (1).在数值计算比如int f ...
- 【DSP开发】解读TI的KeyStone II云技术应用
最近,德州仪器(TI)公司推出6款最新KeyStone II多核SoC,助力云应用.TI公司多核DSP中国市场开发经理蒋亚坚先生向媒体讲解了这6款KeyStone II新产品的特点与目标应用. ...
- Construct String from Binary Tree
You need to construct a string consists of parenthesis and integers from a binary tree with the preo ...
- Box-shadow制作漂亮的外阴影输入框
背景:之前做项目中的一个移动端页面,关于在搜索框中输入信息查找对应的照片 改了几次ui图之后,最终的搜索框的设计图如下: 开始做页面的时候,就想到了用box-shadow 来实现外阴影边框.用bord ...
- .Net高并发解决思路
转自: 本文如有不对之处,欢迎各位拍砖扶正.另源码在文章最下面,大家下载过后先还原一下nuget包,需要改一下redis的配置,rabbitmq的配置以及Ef的连接字符串.另外使用的是CodeFirs ...
- java实现生产者和消费者问题
Java实现生产者和消费者问题 欢迎访问我的个人博客,获取更多有用的东西 链接一 链接二 也可以关注我的微信订阅号:CN丶Moti
- 用java语言(文件和文件流知识点)实现图片的拷贝,从d盘拷贝到e盘
/** * 实现图片的拷贝\ * 注意:用的是文件字节流 */ package com.test4; import java.io.*; public class Demo12_4 { /** * @ ...
- vue中添加与删除,关键字搜索
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...