国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Maximum GCD [水題]

2019-11-08 18:52:24
字體:
來源:轉載
供稿:網友

Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible pair of these integers.

Input

The first line of input is an integer N (1 < N < 100) that determines the number of test cases. The following N lines are the N test cases. Each test case contains M (1 < M < 100) positive integers that you have to find the maximum of GCD.

Output

For each test case show the maximum GCD of every possible pair.

Sample Input

3 10 20 30 40 7 5 12 125 15 25

Sample Output

20 1 25

題解

大水題

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char s[3000];int a[102];int gcd(int a,int b){ return b?gcd(b,a%b):a;}int main(){ int n; scanf("%d",&n);getchar(); while(n--){ gets(s); int len=strlen(s); int u=0; for(int i=0;i<len;i++){ int sum=0; while(i<len&&s[i]!=' '){ sum=sum*10+s[i]-'0'; i++; } a[u++]=sum; } int ans=0; for(int i=0;i<u;i++) for(int j=i+1;j<u;j++) ans=max(ans,gcd(a[i],a[j]));
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 会东县| 临西县| 梁河县| 六盘水市| 文昌市| 萝北县| 双流县| 耿马| 海南省| 屯门区| 郧西县| 桑植县| 河源市| 涪陵区| 清新县| 涡阳县| 泸水县| 炎陵县| 乐清市| 馆陶县| 贵南县| 武陟县| 兰州市| 霍邱县| 波密县| 临清市| 收藏| 漳州市| 津市市| 肃北| 彭水| 南和县| 景泰县| 临城县| 西青区| 若尔盖县| 长丰县| 股票| 灵宝市| 车险| 孟州市|