Given a number n find the number of pairs (x,y) where both x and y are less then n and higest common factor (hcf) of x and y is 1)
Answers
Answered by
0
Answer:
function countPairsBruteForce(X, Y, m, n){
let ans = 0;
for(let i=0; i<m; i++ ){
for(let j=0;j<n;j++){
if ((Math.pow(X[i], Y[j]) > Math.pow(Y[j], X[i]))){
ans += 1;
}
}
}
return ans;
}
Step-by-step explanation:
This problem is recursive and can be broken into sub-problems. We start from the end of the given digit sequence. We initialize the total count of decodings as 0. We recur for two subproblems.
1) If the last digit is non-zero, recur for the remaining (n-1) digits and add the result to the total count.
2) If the last two digits form a valid character (or smaller than 27), recur for remaining (n-2) digits and add the result to the total count.
Similar questions
Math,
5 months ago
Hindi,
5 months ago
Math,
9 months ago
Math,
9 months ago
Political Science,
11 months ago