Tasks Details
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
medium
Calculate the number of elements of an array that are not divisors of each element.
Task Score
100%
Correctness
100%
Performance
100%
You are given an array A consisting of N integers.
For each number A[i] such that 0 ≤ i < N, we want to count the number of elements of the array that are not the divisors of A[i]. We say that these elements are non-divisors.
For example, consider integer N = 5 and array A such that:
A[0] = 3 A[1] = 1 A[2] = 2 A[3] = 3 A[4] = 6For the following elements:
- A[0] = 3, the non-divisors are: 2, 6,
- A[1] = 1, the non-divisors are: 3, 2, 3, 6,
- A[2] = 2, the non-divisors are: 3, 3, 6,
- A[3] = 3, the non-divisors are: 2, 6,
- A[4] = 6, there aren't any non-divisors.
Write a function:
function solution(A);
that, given an array A consisting of N integers, returns a sequence of integers representing the amount of non-divisors.
Result array should be returned as an array of integers.
For example, given:
A[0] = 3 A[1] = 1 A[2] = 2 A[3] = 3 A[4] = 6the function should return [2, 4, 3, 2, 0], as explained above.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..50,000];
- each element of array A is an integer within the range [1..2 * N].
Copyright 2009–2026 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used JavaScript
Time spent on task 15 minutes
Notes
not defined yet
Code: 09:18:19 UTC,
java,
autosave
Code: 09:21:43 UTC,
js,
autosave
Code: 09:23:13 UTC,
js,
autosave
Code: 09:23:32 UTC,
js,
autosave
Code: 09:23:53 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[A[i]] = true
}
}
Code: 09:24:07 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count
}
}
Code: 09:24:17 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
}
Code: 09:25:01 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
}
Code: 09:25:14 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
}
}
Code: 09:25:36 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
}
}
Code: 09:25:49 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
}
Code: 09:26:06 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; i < A.length; i++) {
}
}
}
Code: 09:26:20 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] < A.length; i++) {
}
}
}
Code: 09:26:30 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
}
}
}
Code: 09:26:42 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if()
}
}
}
Code: 09:27:12 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divs[A[i] * k]) {
count[A[i] * k]
}
}
}
}
Code: 09:27:40 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divs[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
}
}
Code: 09:28:11 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divs[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
annswer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:28:14 UTC,
js,
verify,
result: Failed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divs[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
annswer.push(A.length - count[A[i]]);
}
return answer;
}
The submission is being evaluated.
Code: 09:28:24 UTC,
js,
verify,
result: Failed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
annswer.push(A.length - count[A[i]]);
}
return answer;
}
The submission is being evaluated.
Code: 09:28:32 UTC,
js,
verify,
result: Passed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
The submission is being evaluated.
Code: 09:28:48 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:29:08 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:29:18 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:29:48 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:29:58 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:30:17 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
// checking if product of A[i]
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:30:38 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
// checking for products of A[i] exist in A and counting them
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:31:00 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of ) {
for (let k = 2; k * A[i] <= max; k++) {
// checking for products of A[i] exist in A and counting them
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:31:11 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of A[i] exist in A and counting them
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:31:23 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:31:54 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
Code: 09:31:56 UTC,
js,
verify,
result: Passed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
The submission is being evaluated.
Code: 09:32:24 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
Code: 09:32:46 UTC,
js,
verify,
result: Passed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
The submission is being evaluated.
Code: 09:33:05 UTC,
js,
verify,
result: Passed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
The submission is being evaluated.
Code: 09:33:08 UTC,
js,
final,
score: 
100
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
The submission is being evaluated.