Coprime Sequence
来源:互联网 发布:如何更改mysql的密码 编辑:程序博客网 时间:2024/06/01 07:55
Problem Description
Do you know what is called ``Coprime Sequence''? That is a sequence consists of n positive integers, and the GCD (Greatest Common Divisor) of them is equal to 1.
``Coprime Sequence'' is easy to find because of its restriction. But we can try to maximize the GCD of these integers by removing exactly one integer. Now given a sequence, please maximize the GCD of its elements.
``Coprime Sequence'' is easy to find because of its restriction. But we can try to maximize the GCD of these integers by removing exactly one integer. Now given a sequence, please maximize the GCD of its elements.
Input
The first line of the input contains an integer T(1≤T≤10) , denoting the number of test cases.
In each test case, there is an integern(3≤n≤100000) in the first line, denoting the number of integers in the sequence.
Then the following line consists ofn integers a1,a2,...,an(1≤ai≤109) , denoting the elements in the sequence.
In each test case, there is an integer
Then the following line consists of
Output
For each test case, print a single line containing a single integer, denoting the maximum GCD.
Sample Input
331 1 152 2 2 3 241 2 4 8
Sample Output
122
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int a[100009];int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); int flag=0,k=a[0],x,p=a[0]; a[0]=0; for(int i=1;i<n;i++) { x=__gcd(k,a[i]); if(x<k) { a[flag]=p; p=a[i]; flag=i; a[i]=0; k=x; } } int q=0; for(int i=0;i<n;i++) { if(a[i]&&!q) { q=1; k=a[i]; } else { k=__gcd(k,a[i]); } } printf("%d\n",k); } return 0;}
0 0
- Coprime Sequence
- Coprime Sequence
- HDU6025-Coprime Sequence
- HDU6205 Coprime Sequence
- Coprime Sequence(优化)
- HDU 6025 Coprime Sequence
- HDU6025 Coprime Sequence
- hdoj 6025 Coprime Sequence
- HDU 6025 Coprime Sequence
- Coprime Sequence HDU
- hdu 6025 Coprime Sequence
- Coprime Sequence HDU
- HDU6025-Coprime Sequence-简单数学
- hdu6025 Coprime Sequence(2017女生赛)
- Coprime Sequence(前后缀最大公约数)
- HDU6025 Coprime Sequence【前缀GCD+后缀GCD】
- HDU6025 Coprime Sequence (思路题)
- HDU6025 Coprime Sequence (前缀后缀处理)
- PHP Laravel (Homestead)开发环境搭建
- opendir打开后显示的不全
- ES性能调优
- JDBC连接MySql
- 逆向工程核心原理学习笔记(二十二):栈帧9:调用printf()函数
- Coprime Sequence
- c++实现冒泡排序和快速排序
- MEASURING COMPUTER PERFORMANCE
- 领域模型(概念模型) 、逻辑模型、物理模型、贫血模型、充血模型概念总结【待读与标记】
- linux shell 字符串操作(长度,查找,替换)详解
- 百度实习生面试题-按行读取文件
- 记一次 php nginx 502 504 大坑
- 位图
- 【读书笔记】机器学习实战 5.2节 logistics回归