Constraints
Note: Even though you got the exact output, the test cases will fail if you do not use the callback and event concepts as mentioned in the problem statement.
Sample Case 0
Sample Input For Custom Testing 100 1000 Sample Output: Multiples of 100 & 1000 6500
Explanation Multiples of 100 are 100,200,300,......1000 and multiples of 1000 is 1000 in below and including 1000.
Sum = (100+200+............1000) + 1000
Sum = 6500
Sample Case 1
Sample Input For Custom Testing
500 1200
Sample Output:
Multiples of 500 & 1200
1500
I Tried below code :
process.stdin.resume();
process.stdin.setEncoding("ascii");
var input = "";
process.stdin.on("data", function (chunk) {
input += chunk;
});
process.stdin.on("end", function () {
let _input = input.split (" ");
let a = parseInt(_input[0]);
let b = parseInt(_input[1]);
console.log("Multiples of " + a + " & " + b);
var sum = 0;
for (var x = 0; x < 1000; x++)
{
if (x % a === 0 || x % b === 0)
{
sum += x;
}
}
console.log(sum);
});
Code Test out:
Case 1
Input (stdin)
4 6
Multiples of 4 & 6
165834
Multiples of 4 & 6
208666
===============================================
Input (stdin)
3 5
Multiples of 3 & 5
233168
Multiples of 3 & 5
267333
Please help me for this code. My output is not match with this logic.
I got the right solution.
process.stdin.resume();
process.stdin.setEncoding("ascii");
var input = "";
process.stdin.on("data", function (chunk) {
input += chunk;
});
process.stdin.on("end", function () {
const EventEmitter = require('events');
let data = input.split(" ");
n1 = data[0];
n2 = data[1];
// console.log(n1,n2);
let result = 0;
const sum = () => {
for (let i = 0; i <= 1000; i++) {
if (i % n1 == 0) {
result += i;
}
}
for (let j = 0; j <= 1000; j++) {
if (j % n2 == 0) {
result += j;
}
}
console.log(result);
}
setTimeout(sum, 2000);
const event = new EventEmitter();
event.on("MyEvent", () => {
console.log(`Multiples of ${n1} & ${n2}`);
})
event.emit("MyEvent");
});