forked from knakul853/spoj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twosets.cpp
101 lines (79 loc) · 1.36 KB
/
twosets.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<bits/stdc++.h>
using namespace std;
long long int lcm(int x,int y)
{
int a,b,i=1;
if(x>y)
{a=y;b=x;}
else
{a=x;b=y;}
do{
if((b*i)%a==0)
break;
else
i++;
}while(1);
return b*i;
}
long long int gcf(int x,int y)
{
int a,b,i=1;
if(x>y)
{a=y;b=x;}
else
{a=x;b=y;}
do{
if((b*i)%a==0)
break;
else
i++;
}while(1);
return a/i;
}
int main(){
int n,m,l,g,i;
cout<<"enter no of elements to input in first list ";
cin>>m;
cout<<"enter no of elements to input in second list ";
cin>>n;
int a[m],b[n];
for(i=0;i<m;i++)//a
{
cout<<"enter value of elements of first list at position ["<<i+1<<"] ";
cin>>a[i];
}
cout<<"\n";
for(i=0;i<n;i++)//b
{
cout<<"enter value of elements of second list at position ["<<i+1<<"] ";
cin>>b[i];
}
if(n==1)
g=b[0];
else{
g=gcf(b[n-2],b[n-1]);
for(i=(n-3);i>=0;i--)
{
g=gcf(g,b[i]);
}}
if(g==1)
cout<<0;
else{
if(m==1)
l=a[0];
else{
l=lcm(a[m-2],a[m-1]);
for(i=(m-3);i>=0;i--)
{
l=lcm(l,a[i]);;
}
}
int c=0;i=1;
while(g>=(l*i)){
if(g%(l*i)==0)
c++;
i++;
};
cout<<"\n result "<<c;}
return 0;
}