当前位置:网站首页>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;
}
边栏推荐
- Withdrawal of user curve in qualified currency means loss
- ASP. Net core creates razor page and uploads multiple files (buffer mode) (Continued)
- There is no small green triangle on the method in idea
- 关于印发宝安区重点产业项目和总部项目遴选及用地保障实施细则(2022修订版)的通知
- Deficiencies and optimization schemes in Dao
- Notepad++ -- macro (record operation process)
- Software engineering - principles, methods and Applications
- Flume理论
- 从众伤害的是自己
- [notes] take notes again -- learn by doing Verilog HDL – 014
猜你喜欢
Win7 easy connect 提示:选路连接失败,可能当前连接网络异常,请稍后重试
The list of winners in the classic Smurfs of childhood: bluedad's digital collection was announced
苹果iPhone手机升级系统内存空间变小不够如何解决?
ASP. Net core creates razor page and uploads multiple files (buffer mode) (Continued)
Linux Installation mysql5
Tiger painter mengxiangshun's digital collection is on sale in limited quantities and comes with Maotai in the year of the tiger
La collection numérique Meng xiangshun, artiste national du tigre peint, est disponible en quantité limitée et est offerte avec Maotai de l'année du tigre
软件测试逻辑覆盖相关理解
Real time tracking of bug handling progress of the project through metersphere and dataease
Flume configuration 4 - Custom source+sink
随机推荐
Sword finger offer 66 Building a product array
[observation] softcom power liutianwen: embrace change and "follow the trend" to become an "enabler" of China's digital economy
2021 CCPC 哈尔滨 E. Power and Modulo (思维题)
Oracle11.2.0.4-rac cluster hang analysis record
PowerShell command outputs only a list of directories
WPS and Excelle
[compilation principle] type check
[buuctf.reverse] 142_[SUCTF2019]babyunic
ASP. Net core creates razor page and uploads multiple files (buffer mode) (Continued)
Performance improvement at the cost of other components is not good
2022年深圳市福田区支持招商引资若干政策
thinkphp5中的配置如何使用
There is no small green triangle on the method in idea
画虎国手孟祥顺数字藏品限量发售,随赠虎年茅台
Win7 easy connect 提示:选路连接失败,可能当前连接网络异常,请稍后重试
Dynamics CRM: 本地部署的服务器中, Sandbox, Unzip, VSS, Asynchronous还有Monitor服务的作用
Real time tracking of bug handling progress of the project through metersphere and dataease
通过MeterSphere和DataEase实现项目Bug处理进展实时跟进
How to use filters in jfinal to monitor Druid for SQL execution?
【摸鱼神器】UI库秒变低代码工具——表单篇(一)设计