-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.ts
More file actions
68 lines (51 loc) · 1.75 KB
/
Copy pathmain.ts
File metadata and controls
68 lines (51 loc) · 1.75 KB
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
'use strict';
import { WriteStream, createWriteStream } from "fs";
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString: string = '';
let inputLines: string[] = [];
let currentLine: number = 0;
process.stdin.on('data', function(inputStdin: string): void {
inputString += inputStdin;
});
process.stdin.on('end', function(): void {
inputLines = inputString.split('\n');
inputString = '';
main();
});
function readLine(): string {
return inputLines[currentLine++];
}
/*
* Complete the 'getTotalX' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER_ARRAY a
* 2. INTEGER_ARRAY b
*/
function getTotalX(a: number[], b: number[]): number {
// Write your code here
const lcm = (arr: number[]) => {
const gcd2 = (a: number, b: number): number => b ? gcd2(b, a % b) : a;
const lcm2 = (a: number, b: number) => a * b / gcd2(a, b);
return arr.reduce(lcm2, 1);
};
let l = lcm(a), result = 0;
for (let m = l; m <= 100; m += l) {
if (b.every(v => v % m === 0))
result++;
}
return result;
}
function main() {
const ws: WriteStream = createWriteStream(process.env['OUTPUT_PATH']);
const firstMultipleInput: string[] = readLine().replace(/\s+$/g, '').split(' ');
const n: number = parseInt(firstMultipleInput[0], 10);
const m: number = parseInt(firstMultipleInput[1], 10);
const arr: number[] = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
const brr: number[] = readLine().replace(/\s+$/g, '').split(' ').map(brrTemp => parseInt(brrTemp, 10));
const total: number = getTotalX(arr, brr);
ws.write(total + '\n');
ws.end();
}