Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit 6fd2b88

Browse files
committed
Question 1
1 parent 0c4ad38 commit 6fd2b88

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

CA1/Question1.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def cin() :
2+
string = input().strip()
3+
while string == "" :
4+
string = input().strip()
5+
return string
6+
7+
def read_input() :
8+
n,k = cin().split()
9+
n = int(n)
10+
k = int(k)
11+
bags = list()
12+
bags_unsplitted = cin()
13+
biggest_bag = 0
14+
for x in bags_unsplitted.split():
15+
x = int(x)
16+
bags.append(x)
17+
if biggest_bag < x :
18+
biggest_bag = x
19+
return n,k,bags,biggest_bag
20+
21+
def find_gcd_max(n,k,bags,biggest_bag) :
22+
gcd_max = 1
23+
add_to_bags = [0]*n
24+
for gcd in range(2,biggest_bag+1) :
25+
for idx,bag in enumerate(bags) :
26+
remainder = bag%gcd
27+
x = 0
28+
if remainder != 0 :
29+
x = gcd - remainder
30+
add_to_bags[idx] = x
31+
if sum(add_to_bags) <= k :
32+
gcd_max = gcd
33+
return gcd_max
34+
35+
def main() :
36+
n,k,bags,biggest_bag = read_input()
37+
gcd_max = find_gcd_max(n,k,bags,biggest_bag)
38+
print(gcd_max)
39+
main()

0 commit comments

Comments
 (0)