题目大意:
  告诉你一个长度为n的等差数列在模m意义下的乱序值(互不相等),问是否真的存在满足条件的等差数列,并尝试构造任意一个这样的数列。

思路:
  首先我们可以有一个结论:
  两个等差数列相等,当且仅当数字和与平方和分别相等。
  首先求出一开始的数字和和平方和。
  然后我们枚举每一个数作为首项的情况,求出这个数作为首项以后的数字和和平方和,根据数字和求出公差,然后用平方和检验一下。
  然而这样并不能保证一定正确,但至少有大概率是正确的,我们可以O(n)的时间检验一下。
  注意特判n=m的情况。

 #include<cstdio>
#include<hash_set>
typedef long long int64;
inline int getint() {
register char ch;
while(!__builtin_isdigit(ch=getchar()));
register int x=ch^'';
while(__builtin_isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
__gnu_cxx::hash_set<int> set;
const int64 N=;
int64 a[N];
int64 m,n;
inline int64 sqr(const int64 &x) {
return x*x%m;
}
void exgcd(const int64 &a,const int64 &b,int64 &x,int64 &y) {
if(!b) {
x=;
y=;
return;
}
exgcd(b,a%b,y,x);
y-=a/b*x;
}
inline int64 inv(const int64 &x) {
int64 tmp,ret;
exgcd(x,m,ret,tmp);
return (ret+m)%m;
}
int main() {
m=getint(),n=getint();
if(n==m) {
__builtin_puts("0 1");
return ;
}
int64 sum0=,sqrsum0=;
for(register int64 i=;i<n;i++) {
a[i]=getint();
set.insert(a[i]);
sum0=(sum0+a[i])%m;
sqrsum0=(sqrsum0+sqr(a[i]))%m;
}
const int64 c=inv(n*(n-)/);
for(register int64 i=;i<n;i++) {
const int64 sum=((sum0-a[i]*n%m)%m+m)%m;
const int64 sqrsum=((sqrsum0-sqr(a[i])*n%m-a[i]*sum%m*%m)%m+m)%m;
const int64 d=sum*c%m;
if(n*(n-)*(n*-)/%m*sqr(d)%m!=sqrsum) continue;
int64 tmp=a[i];
for(register int64 i=;i<n;i++) {
tmp=(tmp+d)%m;
if(!set.count(tmp)) goto Next;
}
__builtin_printf("%I64d %I64d\n",a[i],d);
return ;
Next:;
}
__builtin_puts("-1");
return ;
}

[CodeForces-763C]Timofey and remoduling的更多相关文章

  1. CF763C Timofey and Remoduling

    题目戳这里. 这道题目纯粹是考思维. 若\(2N \le M\),由于答案肯定是\(s,s+d,\dots,s+(N-1)d\),我们任意枚举两个数\(a,b\),不妨设\(b\)在数列中出现在\(a ...

  2. Codeforces 763A. Timofey and a tree

    A. Timofey and a tree 题意:给一棵树,要求判断是否存在一个点,删除这个点后,所有连通块内颜色一样.$N,C \le 10^5$ 想法:这个叫换根吧.先求出一个点合法即其儿子的子树 ...

  3. Codeforces 764C Timofey and a tree

    Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that th ...

  4. CodeForces - 764B Timofey and cubes(模拟)

    Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Ev ...

  5. Codeforces Round #395 (Div. 2) D. Timofey and rectangles

    地址:http://codeforces.com/contest/764/problem/D 题目: D. Timofey and rectangles time limit per test 2 s ...

  6. Codeforces Round #395 (Div. 2) C. Timofey and a tree

    地址:http://codeforces.com/contest/764/problem/C 题目: C. Timofey and a tree time limit per test 2 secon ...

  7. Codeforces Round #395 (Div. 2)B. Timofey and cubes

    地址:http://codeforces.com/contest/764/problem/B 题目: B. Timofey and cubes time limit per test 1 second ...

  8. 【codeforces 764B】Timofey and cubes

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【codeforces 764C】Timofey and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 某线下赛AWD

    拿别人比赛的来玩一下,或许这就是菜的力量吧. 0x01 任意文件读取: switch ($row['media_type']) { case 0: // 图片广告 ...... break; case ...

  2. Linux内核同步原语之原子操作

    避免对同一数据的并发访问(通常由中断.对称多处理器.内核抢占等引起)称为同步. ——题记 内核源码:Linux-2.6.38.8.tar.bz2 目标平台:ARM体系结构 原子操作确保对同一数据的“读 ...

  3. iTextSharp操作pdf之pdfCreater

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. nginx 查看当前的连接数

    netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a,S[a]}' https://www.cnblogs.com/lianzhil ...

  5. PDO和mysqli对比

    PHP中,如何选择PDO和mysqli呢?本文做个简单的比较 1)总的比较   PDO MYSQLI 数据库支持 12种不同的数据库支持 支持MYSQL API OOP OOP和过程 命名参数 支持 ...

  6. 看看PHP迭代器的内部执行过程

    class myIterator implements Iterator { private $position = 0; private $array = array( "first_el ...

  7. Crypt加密函数简介(C语言)

    定义函数 char * crypt (const char *key,const char * salt); 函数说明 crypt是个密码加密函数,它是基于Data Encryption Standa ...

  8. Hive入门学习随笔(一)

    Hive入门学习随笔(一) ===什么是Hive? 它可以来保存我们的数据,Hive的数据仓库与传统意义上的数据仓库还有区别. Hive跟传统方式是不一样的,Hive是建立在Hadoop HDFS基础 ...

  9. 720P、1080P、4K是什么意思?

    什么是像素? 中文全称为图像元素.像素仅仅只是分辨率的尺寸单位,而不是画质. 从定义上来看,像素是指基本原色素及其灰度的基本编码. 像素是构成数码影像的基本单元,通常以像素每英寸PPI(pixels ...

  10. 解决wordpress无法发送邮件的问题|配置好WP-Mail-SMTP的前提

    我的WordPress主机是万网的,配置WP-Mail-SMTP时一直无法发送邮件,导致设置失败.经过多次询问度娘才找到了解决wordpress无法发送邮件的方法,在这里把这个wordpress技巧分 ...