-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6.difference_of_sum
36 lines (32 loc) · 1.17 KB
/
6.difference_of_sum
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
"""6. Difference Of Sum
Write a function differenceofSum(a,b) which will take two integers as an argument. You’ve to obtain the total of all the integers ranging
from 1 to n (both inclusive) that are not divisible by b. You should also return the distinction between the sum of the integers
which are not divisible by b with the sum of the integers divisible by b?
Consider: a and b are greater than 0. i.e a>0 and b>0. And their sum should lies between the integral range.
Sample Test Case 1:
Input:
a=6 and b=30
Output:
285
Explanation:
The integers that are divisible by 6 are 6, 12, 18, 24, and 30 and their sum is 90.
The integers that are not divisible by 6 are 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 25, 26, 27, 28 and 29.
And their addition is 375.
The difference between them is (375 – 90) = 285.
Sample Test Case 2: Input:
a=10
b=3
Output:
19
"""
x,y=map(int,input().split(" "))
if(x<y):
a,b=x,y
else:
a,b=y,x
factors_a=[]
not_factors_a=[]
factors_a=[x for x in range(a,b+1) if x%a==0]
not_factors_a=[x for x in range(1,b+1) if x not in factors_a]
print(factors_a,"\n",not_factors_a)
print(sum(not_factors_a)-sum(factors_a))