between two sets problem hackerrank solution in c

Solutions on MaxInterview for between two sets problem hackerrank solution in c by the best coders in the world

showing results for - "between two sets problem hackerrank solution in c"
Lilie
14 Oct 2020
1#include<stdio.h>
2int main() {
3    int n,t,flag1,flag2,j,total=0,i;
4    int m;
5    scanf("%i %i", &n, &m);
6    int a[n],b[m];
7    for (i = 0; i < n; i++) 
8       scanf("%i",&a[i]);
9    
10    for (i = 0; i < m; i++) 
11       scanf("%i",&b[i]);
12    
13    for(t=n;t<=b[0];t++)
14    {
15        flag1=0;
16        flag2=0;
17        for(i=0;i<n;i++)
18        {
19            if(t%a[i] !=0)
20            {
21                flag1=1;
22                break;
23            }
24        }
25        if(flag1 == 0)
26        {
27            for(j=0;j<m;j++)
28            {
29                if(b[j]%t !=0)
30                {
31                    flag2=1;
32                    break;
33                }
34            }
35        }
36        if(flag1 == 0 && flag2 == 0)
37            total++;
38    }
39    printf("%d\n", total);
40    return 0;
41}
Filippo
07 Mar 2017
1# Complete the 'getTotalX' function below.
2
3def getTotalX(a, b):
4    maxA = max(a)
5    minB = min(b)
6    count = 0
7    for num in range(maxA, minB + 1):
8        left = all([num % numA == 0 for numA in a])
9        right = all([numB % num == 0 for numB in b])
10        count += left * right
11    return count