-
Notifications
You must be signed in to change notification settings - Fork 0
/
coprim2.cpp
54 lines (52 loc) · 1.15 KB
/
coprim2.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
#include<stdio.h>
#define max(a,b) a>b?a:b
long long int dp[10008];
int gcd(int a, int b)
{
if(b == 0)
{
return a;
}
else
{
return gcd(b, a % b);
}
}
int main()
{
int i,t,n;
scanf("%d",&t);
//int aaa=0;
//for(i=0;i<4000;i++)
//aaa+=i;
for(i=0;i<t;i++)
{
scanf("%d",&n);
int a[n];
scanf("%d",&a[0]);
int j,maxi=a[0];
for(j=1;j<n;j++)
{scanf("%d",&a[j]);maxi=max(maxi,a[j]);}
printf("%d\n",maxi);
for(j=0;j<10008;j++)
dp[j]=0;
for(j=0;j<n;j++)
{
int value=a[j];
printf(" %d \n",value);
int x,k;
for(k=1;k<=maxi;k++)
{
if(dp[k]>0)
{
x=gcd(value,k);
dp[x]+=(dp[k]);
printf("%d %lld\n",x,dp[x]);
}
}
dp[value]+=1;
}
printf("%lld\n",dp[1]);
}
return 0;
}