Today I have solved problem in javascript
Given integers M and N, write a program that counts how many positive integer pairs (a, b) satisfy the following conditions:
a + b = M
a XOR b = N
const M = 10;
const N = 5;
function countIntegerPairs(M, N) {
let count = 0;
for (let a = 0; a <= M; a++) {
let b = M - a;
if ((a ^ b) === N) {
count++;
}
}
return count;
}
console.log(countIntegerPairs(M, N));
Output:
0
Comments
Post a Comment