-
Notifications
You must be signed in to change notification settings - Fork 96
/
6.5.cpp
45 lines (39 loc) · 850 Bytes
/
6.5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* 题目名称:最简真分数
* 题目来源:北京大学复试上机题
* 题目链接:http://t.cn/AiCua2g8
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 600 + 10;
int arr[MAXN];
int GCD(int a, int b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
int main() {
int n;
while (scanf("%d", &n) != EOF) {
if (n == 0) {
break;
}
for (int i = 0; i < n; ++i) {
scanf("%d", &arr[i]);
}
int answer = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (GCD(arr[i], arr[j]) == 1) {
answer++;
}
}
}
printf("%d\n", answer);
}
return 0;
}