国产探花免费观看_亚洲丰满少妇自慰呻吟_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]));
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蕉岭县| 隆化县| 临猗县| 抚宁县| 清苑县| 吴川市| 漯河市| 盐源县| 偃师市| 平遥县| 孟村| 呼和浩特市| 和静县| 东方市| 平阴县| 东阿县| 桐庐县| 古丈县| 肥东县| 武城县| 兰坪| 中江县| 固原市| 长治县| 岱山县| 滨州市| 平原县| 淳安县| 河北省| 乃东县| 广水市| 黔江区| 贵港市| 宝清县| 涿州市| 益阳市| 岳普湖县| 通辽市| 丹阳市| 正阳县| 重庆市|