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

Popular posts from this blog

Building a Full-Stack Student Management System with React.js and NestJS

Today I have solved the problem in javascript

Today I have solved problem in javascript