dada的GCD ( jxnu acm新生选拔赛)
1007 dada的GCD,输入格式描述有误,已修正dada的GCD
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 36 Accepted Submission(s) : 8
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
C语言都学过了怎么计算两个数的最大公约数,而一段区间[L,R]的GCD即这段区间所有数的最大公约数。现在给你一串长度为n的序列,如果对于序列的任意子区间[L,R],都有这段区间的gcd>=2,那么这段序列就叫做dada的GCD序列。
n<=10^4
序列的每个数小于10^9Input
第一行有一个整数t,代表t组数据
每组输入有一个正整数n,
随后一行n个正整数。
大量输入,使用cin的同学请关闭stdio同步Output
如果是dada的GCD序列,就输出Yes,反之输出NoSample Input
2
3
2 6 4
3
4 6 9Sample Output
Yes
NoAuthor
Luke叶Source
jxnu
1 #include<iostream>
2 #include<stdio.h>
3 #include<string.h>
4 #include<algorithm>
5 using namespace std;
6 int a[100050];
7 int s[1005];
8 bool su(int x){
9 if(x%2==0) return false;
10 else {
11 for(int i=3;i*i<=x;i=i+2){
12 if(x%i==0) return false;
13 }
14 return true;
15 }
16 }
17 int main()
18 {
19 int T;
20 s[0]=2;
21 int t=1;
22 for(int i=3;t<1003;i++)
23 if(su(i)){
24 s[t]=i;
25 t++;
26 }
27 cin>>T;
28 while(T--)
29 {
30 int n;
31 scanf("%d",&n);
32 memset(a,0,sizeof(a));
33 for(int i=0;i<n;i++)
34 scanf("%d",&a[i]);
35 bool flag=false;
36 for(int i=0;i<t;i++)
37 {
38 int sum=0;
39 for(int j=0;j<n;j++){
40 if(a[j]%s[i]==0){
41 sum++;
42 }
43 }
44 if(sum==n){
45 flag=true;
46 break;
47 }
48 }
49 if(flag) cout<<"Yes"<<endl;
50 else cout<<"No"<<endl;
51 }
52 return 0;
53 }
正版AC代码:
1 #include<iostream>
2 #include<stdio.h>
3 using namespace std;
4 int a[10005];
5 int gcd(int a,int b)
6 {
7 if(a==0) return b;
8 else{
9 return gcd(b%a,a);
10 }
11 }
12 int main()
13 {
14 int T;
15 cin>>T;
16 while(T--){
17 int n;
18 cin>>n;
19 for(int i=0;i<n;i++){
20 scanf("%d",&a[i]);
21 }
22 if(n==1){
23 if(a[0]>=2) cout<<"Yes"<<endl;
24 else cout<<"No"<<endl;
25 }else{
26 int ans=gcd(a[0],a[1]);
27 bool flag=true;
28 for(int i=2;i<n;i++){
29 ans=gcd(ans,a[i]);
30 if(ans<2){
31 flag=false;
32 break;
33 }
34 }
35 if(flag) cout<<"Yes"<<endl;
36 else cout<<"No"<<endl;
37 }
38 }
39 return 0;
40 }
dada的GCD ( jxnu acm新生选拔赛)的更多相关文章
- JXNU 新生选拔赛
1001 最小的数 Problem Description 定义一种正整数集合K,集合中有N个数,集合中元素Ki(1<=i<=N)是包含i个不同质因子的最小的数.因为Ki可能会很大,所以将 ...
- 2019 年「计算机科学与工程学院」新生赛 暨ACM集训队选拔赛 # 1
T1 请问这还是纸牌游戏吗 https://scut.online/p/567 这道题正解据说是方根 这里先放着等以后填坑吧qwq 但是由于这道题数据是随机的 所以其实是有各种水法的(但是我比赛根本没 ...
- 2018 ACM 网络选拔赛 青岛赛区
一些题目的代码被网站吞了…… Problem B. Red Black Tree http://acm.zju.edu.cn/onlinejudge/searchProblem.do?contestI ...
- GCD XOR, ACM/ICPC Dhaka 2013, UVa12716
不同的枚举方法,效率完全不同.值得记录一下! #include <cstdio> #include <cstring> , count = ; ]; void pre() { ...
- 2018 ACM 网络选拔赛 北京赛区
A Saving Tang Monk II #include <bits/stdc++.h> using namespace std; ; struct node { int x,y,z, ...
- 2018 ACM 网络选拔赛 徐州赛区
A. Hard to prepare #include <cstdio> #include <cstdlib> #include <cmath> #include ...
- 2018 ACM 网络选拔赛 焦作赛区
A. Magic Mirror #include <cstdio> #include <cstdlib> #include <cmath> #include < ...
- 2018 ACM 网络选拔赛 沈阳赛区
B. Call of Accepted #include <cstdio> #include <cstdlib> #include <cmath> #include ...
- 2018 ACM 网络选拔赛 南京赛区
A. An Olympian Math Problem #include <cstdio> #include <cstdlib> #include <cmath> ...
- 2019年华南理工大学软件学院ACM集训队选拔赛 Round1
TIps: 1.所有代码中博主使用了scanf和printf作为输入输出 2.代码中使用了define LL long long 所以在声明变量的时候 LL其实就等价于long long 希望这两点 ...
随机推荐
- 完全卸载MySQL服务的方法
1. 重新运行安装文件,单击remove移除mysql.此时安装目录中的文件没有完全移除,需要手动删除安装目录的Mysql文件夹. 2. 如果MySQL服务没有移除的话,以管理员方式运行cmd命令:s ...
- Linux安装达梦数据库DM8
1.简介描述 DM8是达梦公司在总结DM系列产品研发与应用经验的基础上,坚持开放创新.简洁实用的理念,推出的新一代自研数据库.DM8吸收借鉴当前先进新技术思想与主流数据库产品的优点,融合了分布式.弹性 ...
- .NET 8 的 green thread 异步模型被搁置了
.NET 平台上的green thread 异步模型实验结果最近出来了,具体参见:https://github.com/dotnet/runtimelab/issues/2398 ,实验结果总结一下就 ...
- Solution -「香港网络赛 2016」A+B Problem
Description Link. 给出一个长度为 \(n\) 的序列 \(a\),问有序三元组 \((a_{i},a_{j},a_{k})\) 使得 \(i\neq j\neq k\) 且 \(a_ ...
- Linux部署项目常用命令(持续更新)
防火墙配置 # 启动防火墙服务 systemctl start firewalld # 关闭防火墙服务 systemctl stop firewalld # 查看防火墙服务状态 systemctl s ...
- MySQL实战实战系列 06 全局锁和表锁 :给表加个字段怎么有这么多阻碍?
今天我要跟你聊聊 MySQL 的锁.数据库锁设计的初衷是处理并发问题.作为多用户共享的资源,当出现并发访问的时候,数据库需要合理地控制资源的访问规则.而锁就是用来实现这些访问规则的重要数据结构. 根据 ...
- 第一个 Go 程序"hello,world" 与 main 函数和Go常用基本命令
第一个 Go 程序"hello,world" 与 main 函数和Go常用基本命令 目录 第一个 Go 程序"hello,world" 与 main 函数和Go ...
- chatgpt 非常不稳定
写一个飞机大战游戏 很抱歉,作为一名语言模型,我没有具体的编程功能,无法直接为您编写一个飞机大战游戏.不过,我可以为您提供一些创建飞机大战游戏的一般步骤和建议. 设计游戏元素 首先,您 ...
- Java面向对象编程的三大特性:封装、继承、多态。
一.封装 封装的核心在于私有化(private),大部分情况下,来封装对象的属性,很少有封装方法的.通过将对象的属性封装,提供对外的公共方法来访问属性是最常见的方式. public static cl ...
- MyBatis foreach循环批量修改数据时报错
报错如下 org.springframework.jdbc.BadSqlGrammarException: ### Error updating database. Cause: java.sql.S ...