-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecnuoj2957.cpp
79 lines (78 loc) · 1.49 KB
/
ecnuoj2957.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
struct frac
{
int up=-1;
int down=-1;
};
int gcd(int a,int b)
{
int c=max(a,b);
int d=min(a,b);
while (c%d!=0)
{
int temp=d;
d=c%d;
c=temp;
}
return d;
}
int num(vector<int> v)
{
set<frac> s;
set<int> nums;
for (size_t i = 0; i < v.size(); i++)
{
nums.insert(v[i]);
}
vector<int> nv;
for(set<int>::iterator sit=nums.begin();sit!=nums.end();sit++)
{
nv.push_back(*sit);
}
sort(nv.begin(),nv.end());
for(int i=0;i<nv.size();i++)
{
for(int j=i+1;j<nv.size();j++)
{
frac f;
if(gcd(nv[i],nv[j])==1)
{
f.down=nv[j];
f.up=nv[i];
s.insert(f);
}
else
{
f.down=nv[j]/gcd(nv[i],nv[j]);
f.up=nv[i]/gcd(nv[i],nv[j]);
s.insert(f);
}
}
}
return s.size();
}
int main()
{
int T=0;
scanf("%d",&T);
for (size_t i = 0; i < T; i++)
{
int n=0;
scanf("%d",&n);
vector<int> v;
while (n>0)
{
int a=0;
scanf("%d",&a);
v.push_back(a);
n--;
}
cout<<"case #"<<i<<":"<<endl;
cout<<num(v)<<endl;
}
return 0;
}