-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCOPRIME3.cpp
More file actions
55 lines (47 loc) · 737 Bytes
/
Copy pathCOPRIME3.cpp
File metadata and controls
55 lines (47 loc) · 737 Bytes
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
#include<iostream>
#include<stdio.h>
using namespace std;
int gcd(int a, int b)
{
if (a == 0 || b == 0)
return 0;
if (a == b)
return a;
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
int main(){
int n;
cin>>n;
int ar1[n];
for(int x=0;x<n;x++){
cin>>ar1[x];
}
int ar[n][n];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
ar[i][j]=0;
for(int x=0;x<n;x++){
for(int y=x+1;y<n;y++){
ar[x][y]=gcd(ar1[x],ar1[y]);
}
}
/* cout<<endl;
for(int x=0;x<n;x++){
for(int y=0;y<n;y++){
cout<<ar[x][y]<<" ";
}
cout<<endl;
}*/
int count=0;
for(int x=0;x<n;x++){
for(int y=x+1;y<n;y++){
if(ar[x][y]==1){
count+=n-y-1;
}
}
}
cout<<count;
return 0;
}