A. Serval and Mocha‘s Array codeforces 1789A
Problem - A - Codeforces
题目大意:有一长为n的数组,可以随意改变数组中元素的顺序,问能否使任意的前缀数组都满足所有数的gcd<=该数组长度
2<=n<=5e4
思路:求多个数的gcd时,随着数字增多,gcd不会变大,所以我们只要满足前两个数的gcd<=2即可,那么我们枚举每两个数,只要找到两个数gcd<=2,答案就是YES
//#include<__msvc_all_public_headers.hpp>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b)
{//求两个数的最大公因数return b ? gcd(b, a % b) : a;
}
const int N = 105;
int a[N];
int main()
{cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);int t;cin >> t;while (t--){int n;cin >> n;int now;int gc;for (int i = 1; i <= n; i++){cin >> a[i];}bool flag = 0;for (int i = 1; i <= n; i++){for (int j = i + 1; j <= n; j++){if (gcd(a[i], a[j]) <= 2){flag = 1;break;}}}if (flag){cout << "YES" << endl;}else{cout << "NO" << endl;}}return 0;
}
A. Serval and Mocha‘s Array codeforces 1789A相关推荐
- Powerful array CodeForces - 86D (莫队算法)
An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, a ...
- Greg and Array CodeForces - 296C(差分数组+线段树)
Greg has an array a = a1, a2, -, an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ...
- Interesting Array CodeForces - 483D(思维+线段树)
We'll call an array of n non-negative integers a[1], a[2], -, a[n] interesting, if it meets m constr ...
- Constructing the Array CodeForces - 1353D(数据结构+分类+建设性算法)
题意: 有长度为 n 的数组 a ,全为 0,接下来循环 n 次,每次选出一段最长的连续区间 [l, r](全为 0 ,如果一样长,就选最左边的). 如果 r−l+1 是奇数,那么 a[l+r2]=i ...
- Most Unstable Array CodeForces - 1353A(数学+贪心+建设性算法)
题意: 给定 n, m,构造出一个长度为 n 的数组 a,使得数组的和为 m,在此条件下∑i=1n−1∣ai−ai−1∣\sum_{i=1}^{n-1}|a_{i}−a_{i-1}|i=1∑n−1∣ ...
- A. Arithmetic Array Codeforces Round #726 (Div. 2)
A. Arithmetic Array An array b of length k is called good if its arithmetic mean is equal to 1. More ...
- 【Codeforces Round #853 (Div. 2)】C. Serval and Toxel‘s Arrays【题解】
题目 Toxel likes arrays. Before traveling to the Paldea region, Serval gave him an array a a a as a gi ...
- Codeforces Round #650 (Div. 3)(A-C)
Short Substrings CodeForces - 1367A 思路:除了第一位和最后一位之外,剩下的两个之中取一个就行. 代码如下: #include<bits/stdc++.h> ...
- Codeforces Round #642 (Div. 3)(AB)
Most Unstable Array CodeForces - 1353A 思路:最大是2*m,特判n= =1和n==2的情况. 代码如下: #include<bits/stdc++.h> ...
最新文章
- 图像切割之(一)概述
- 浅析在网站优化工作中是如何优化网站流量的?
- go语言中将函数作为变量传递
- android获取网络图片
- 每日一笑 | 坐牢吗?学编程那种~
- 为什么大公司一定要使用DevOps
- 基于TCP协议的网络程序(基础学习)
- android设置window背景颜色,android – 设置标题背景颜色
- 操作系统内存管理问题集锦
- Rust最受喜爱却少有人用,Python仅排第六,2021全球开发者调查报告出炉
- Java并发编程之LinkedBlockingQueue
- 【Sniffer】如何查看Sniffer截获的数据内容
- 004--MySql数据库的淘宝商城数据库设计
- nature:2021年最值得关注的技术
- Word导出pdf时Origin图片出现重影(重叠)
- java 工厂模式例子_java 工厂模式简单介绍及例子
- Android架构师绩效考核表,半年绩效考核总结(7.9)
- 学而思的python课怎么样_学而思老师怎么样?上课效果好吗?
- 华大单片机HC32L130/HC32L136红外端口配置
- 第四课:股票,多数人的找死,少数人的等死
热门文章
- 朴素贝叶斯文本分类java_基于朴素贝叶斯的文本分类算法
- Js手写面试题5-Promise
- POJ 1300 Door Man(欧拉回路判定)
- YTU OJ 2377: Doorman
- Selenium WebDriver——如何测试REST API
- IOS音视频(四十三)AVFoundation 之 Audio Session
- C4D阿诺德渲染器:C4DtoA for Cinema 4D S24 for mac
- 软件测试动画ppt,五、动态测试后处理.ppt
- 研发源代码防泄密加密软件分析
- C#Dictionary实例详解