当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

【编译原理】语法分析

Introduction to the latest version 24.1.0.360 update of CorelDRAW

JMeter BeanShell explanation and thread calling

【编译原理】类型检查

Flume理论

Finally, Amazon~

【Try to Hack】vulnhub narak

4-1 port scanning technology

Real time tracking of bug handling progress of the project through metersphere and dataease

Flume configuration 2 - ganglia for monitoring
随机推荐
npm ERR! fatal: early EOF npm ERR! fatal: index-pack failed
What is a database? Database detailed notes! Take you into the database ~ you want to know everything here!
Static static member variables use @value injection
【Try to Hack】vulnhub narak
Linux安装MySQL8
Union find
Tiger painter mengxiangshun's digital collection is on sale in limited quantities and comes with Maotai in the year of the tiger
MySQL remote connection
1404万!四川省人社厅关系型数据库及中间件软件系统升级采购招标!
Notepad++--宏(记录操作过程)
Zotero期刊自動匹配更新影響因子
proxmox集群节点崩溃处理
Sword finger offer 66 Building a product array
Dynamics CRM: 本地部署的服务器中, Sandbox, Unzip, VSS, Asynchronous还有Monitor服务的作用
使用Gunicorn部署web.py应用
There are more than 20 databases in a MySQL with 3306 ports. How can I backup more than 20 databases with one click and do system backup to prevent data from being deleted by mistake?
Sword finger offer 59 - I. maximum value of sliding window
软件测试逻辑覆盖相关理解
Golang基础学习
How to solve the problem of insufficient memory space in Apple iPhone upgrade system?