当前位置:网站首页>2021 CCPC 哈尔滨 E. Power and Modulo (思维题)
2021 CCPC 哈尔滨 E. Power and Modulo (思维题)
2022-06-29 20:03:00 【GHOSTANDBREAD】
思路:
这个题搞清楚那几种情况,特判一下第一个数,需要注意的是不能简单直接的按照题意使用
pow(2,n - 1),这样会wa,因为n是1e5的数量级。这里要用一个规律,即2^(n - 1) 的序列的规律是 前一项 * 2 = 后一项,则2^(n - 1) mod M之后,其规律没有变,依然是 前一项 * 2 = 后一项
代码:
#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;
}
边栏推荐
猜你喜欢

【摸鱼神器】UI库秒变低代码工具——表单篇(一)设计

Connaissance générale des paramètres de sécurité du serveur Cloud

How to set a pod to run on a specified node

CorelDRAW最新24.1.0.360版本更新介绍讲解

畫虎國手孟祥順數字藏品限量發售,隨贈虎年茅臺

Koa 源码剖析

ASP. Net core creates razor page and uploads multiple files (buffer mode) (Continued)
![[observation] softcom power liutianwen: embrace change and](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[observation] softcom power liutianwen: embrace change and "follow the trend" to become an "enabler" of China's digital economy

【编译原理】类型检查

JMeter BeanShell explanation and thread calling
随机推荐
Flume configuration 2 - ganglia for monitoring
Hangfire详解
【译】十二因子应用(四)
[boutique] detailed explanation of Pinia
【Try to Hack】vulnhub narak
Nutch2.1分布式抓取
Talk about the delta configuration of Eureka
偶然发现了另一种跨域方式,不知道有没有人这么玩过
One hour to build a sample scenario sound network to release lingfalcon Internet of things cloud platform
Common knowledge of ECS security settings
Spark存储体系底层架构剖析-Spark商业环境实战
攻防演练中的防守基石——全方位监控
As the "only" privacy computing provider, insight technology is the "first" to settle in the Yangtze River Delta data element circulation service platform
Flume配置2——监控之Ganglia
Notepad++ -- macro (record operation process)
Ovirt database modify delete node
Zotero期刊自動匹配更新影響因子
Sword finger offer 59 - ii Maximum value of the queue
命令执行(RCE)漏洞
Flume configuration 4 - Custom source+sink