当前位置:网站首页>2021 CCPC Harbin E. power and modulo (thinking questions)
2021 CCPC Harbin E. power and modulo (thinking questions)
2022-06-29 20:10:00 【GHOSTANDBREAD】
Ideas :
This question makes clear what kinds of situations , Let's judge the first number , It should be noted that it cannot be used simply and directly according to the meaning of the question
pow(2,n - 1), This will wa, because n yes 1e5 The order of magnitude . Here is a rule , namely 2^(n - 1) The law of the sequence of is The previous one * 2 = The latter , be 2^(n - 1) mod M after , The law has not changed , Is still The previous one * 2 = The latter
Code :
#include<iostream>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int tmp[100010];
int x = 1;
int t;
bool flag, flag1;
int main() {
scanf("%d", &t);
int n;
while(t --) {
scanf("%d", &n);
flag = false, flag1 = false, x = 1;
for(int i = 1; i <= n; i ++)
scanf("%d", &tmp[i]);
if(tmp[1] == 0) {
for(int i = 1; i <= n; i ++) {
if(tmp[i] != 0) {
flag = true;
break;
}
}
}
else if(tmp[1] > 1) flag = true;
else {
for(int i = 2; i <= n; i ++) {
if(tmp[i - 1] * 2 != tmp[i]) {
x = tmp[i - 1] * 2 - tmp[i];
flag1 = true;
break;
}
}
if(flag1) {
for(int i = 2; i <= n; i ++) {
if(tmp[i - 1] * 2 % x != tmp[i]) {
flag = true;
break;
}
}
} else
flag = true;
}
if(!flag) printf("%d\n", x);
else printf("-1\n");
}
return 0;
}
边栏推荐
- Static static member variables use @value injection
- Introduction to the latest version 24.1.0.360 update of CorelDRAW
- ETCD数据库源码分析——服务端PUT流程
- 【Try to Hack】vulnhub narak
- 剑指 Offer 59 - I. 滑动窗口的最大值
- Deficiencies and optimization schemes in Dao
- Flume-ng配置
- Notepad++--宏(记录操作过程)
- Codeforces Global Round 21 C D E
- [notes] take notes again -- learn by doing Verilog HDL – 014
猜你喜欢
随机推荐
fastadmin后台设置单选按钮
A great open source image watermarking solution
lock4j--分布式锁中间件--自定义获取锁失败的逻辑
【Try to Hack】vulnhub narak
PHP implementation extracts non repeated integers (programming topics can be the fastest familiar functions)
【编译原理】语义分析
Talk about the delta configuration of Eureka
Zotero期刊自动匹配更新影响因子
关于印发宝安区重点产业项目和总部项目遴选及用地保障实施细则(2022修订版)的通知
雪花id,分布式唯一id
As the "only" privacy computing provider, insight technology is the "first" to settle in the Yangtze River Delta data element circulation service platform
【译】十二因子应用(四)
14.04 million! Sichuan provincial human resources and social security department relational database and middleware software system upgrade procurement bidding!
Golang基础学习
剑指 Offer 59 - I. 滑动窗口的最大值
并查集(Union-Find)
Command execution (RCE) vulnerability
XSS vulnerability
【编译原理】类型检查
深入Go底层原理,重写Redis中间件实战无密







![[compilation principle] type check](/img/fc/458871e2df4e0384f65e09faa909d7.png)
