题目大意:
  告诉你一个长度为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. 【leetcode 简单】第三十八题 两数之和 II - 输入有序数组

    给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值index1 和 index2,其中 index1 必须小于 index2. 说明: 返回的下标值( ...

  2. docker 镜像导入和导出

    使用 docker commit 即可把这个容器变为一个镜像 docker commit 8d93082a9ce1 ubuntu:myubuntu 这时候 docker 容器会被创建为一个新的 Ubu ...

  3. thinkphp 5.0 代码执行漏洞

    https://github.com/vulhub/vulhub/blob/master/thinkphp/5-rce docker-compose -f /home/root/compose.yml ...

  4. vue头像上传

    项目四知识点 默认头像 选择头像 <template> <div class="adatar"> <img :src="adatar?ada ...

  5. Oracle中的dual

    简介,摘自百度百科: Oracle提供的最小的表,不论进行何种操作(不要删除记录),它都只有一条记录——'X'. 例如:执行select * from dual,里面只有一条记录:执行insert i ...

  6. LightOJ 1323 Billiard Balls(找规律(蚂蚁爬木棍))

    题目链接:https://vjudge.net/contest/28079#problem/M 题目大意: 一个边界长为L宽为W的平面同时发射n个台球,运动K秒,台球碰到桌面及两(多)个台球相撞情况如 ...

  7. C语言俄罗斯方块

    #include <windows.h> #include <stdio.h> #include <time.h> #include <conio.h> ...

  8. windows 下 nginx 配置虚拟主机

    1. 在 nginx 的配置文件 nginx.conf 里面 引入虚拟主机配置文件,以后所有的虚拟主机配置文件都在写这个文件里 include       vhost.conf; (或者新建vhost ...

  9. Python中的json操作

    Python中的json操作 标签(空格分隔): python 编码 json 字符串前缀问题 字符串前缀可以有r,u r:表示原始(raw)字符串,比如'\n'不会被转义.常用于正则. u:表示un ...

  10. django rest_framework比较完整的自定义实现样例

    里面有自定义的更新策略, 序列化时,考虑nest及显示. 很有参考意义. 然后,前端,可以考虑用angular.js或vue.js实现. 每次以token进行认证. url.py router = D ...