-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathBetween Two Sets.py
140 lines (70 loc) · 2.71 KB
/
Between Two Sets.py
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/python3
import math
import os
import random
import re
import sys
def factor(i,a):
for j in a:
if i%j == 0:
pass
else:
return False
return True
def factor2(i,b):
for j in b:
if j%i == 0:
pass
else:
return False
return True
def getTotalX(a, b):
a_list1 = []
a_factor_list1 = []
b_factor_list1 = []
for i in range(a[0],b[0]+1):
a_list1.append(i)
for i in a_list1:
if(factor(i,a)):
a_factor_list1.append(i)
for i in a_factor_list1:
if(factor2(i,b)):
b_factor_list1.append(i)
return len(b_factor_list1)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
arr = list(map(int, input().rstrip().split()))
brr = list(map(int, input().rstrip().split()))
total = getTotalX(arr, brr)
fptr.write(str(total) + '\n')
fptr.close()
# You will be given two arrays of integers and asked to determine all integers that satisfy the following two conditions:
# The elements of the first array are all factors of the integer being considered
# The integer being considered is a factor of all elements of the second array
# These numbers are referred to as being between the two arrays. You must determine how many such numbers exist.
# For example, given the arrays and , there are two numbers between them: and . , , and for the first value. Similarly, , and , .
# Function Description
# Complete the getTotalX function in the editor below. It should return the number of integers that are betwen the sets.
# getTotalX has the following parameter(s):
# a: an array of integers
# b: an array of integers
# Input Format
# The first line contains two space-separated integers, and , the number of elements in array and the number of elements in array .
# The second line contains distinct space-separated integers describing where .
# The third line contains distinct space-separated integers describing where .
# Constraints
# Output Format
# Print the number of integers that are considered to be between and .
# Sample Input
# 2 3
# 2 4
# 16 32 96
# Sample Output
# 3
# Explanation
# 2 and 4 divide evenly into 4, 8, 12 and 16.
# 4, 8 and 16 divide evenly into 16, 32, 96.
# 4, 8 and 16 are the only three numbers for which each element of a is a factor and each is a factor of all elements of b.