<script>
function
checkIfUnequal(n,q)
{
let s1 = n.toString();
let a =
new
Array(10);
for
(let i = 0; i < a.length; i++)
{
a[i] = 0;
}
for
(let i = 0; i < s1.length; i++)
a[s1[i].charCodeAt(0) - '0
'.charCodeAt(0)]++;
// Calculate corresponding product
let prod = n * q;
// Convert the product to string
let s2 = prod.toString();
// Using the hash check if any digit of
// product matches with the digits of
// input number
for (let i = 0; i < s2.length; i++)
{
// If yes, return false
if (a[s2[i].charCodeAt(0) - '
0
'.charCodeAt(0)] > 0)
return false;
}
// else, return true
return true;
}
// Function to count numbers in the range [l, r]
// such that all of the digits of the number and
// it'
s product
with
q are unequal
function
countInRange(l,r,q)
{
let count = 0;
for
(let i = l; i <= r; i++)
{
if
(checkIfUnequal(i, q))
count++;
}
return
count;
}
let l = 10, r = 12, q = 2;
document.write(countInRange(l, r, q));
</script>