Help me in solving COUNTN problem

My issue

I am unable to debug this code in order to find the runtime error its causing

My code

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

let cases;
let currentCase = 0;

rl.question('', (input) => {
  cases = parseInt(input.trim());
  rl.setPrompt('');
  rl.prompt();
});

rl.on('line', (input) => {
  if (currentCase < cases) {
    const vars = input.trim().split(' ');
    calculate(parseInt(vars[0]));
    currentCase++;
    rl.prompt();
  } else {
    rl.close();
  }
});

rl.on('close', () => {
  process.exit(0);
});

function calculate(raw) {
  let sum = 0;

  function findNumbers(i) {
    if (i > raw * raw) {
      console.log(sum);
      return;
    }

    if (i % raw === 0 && isHighestDivisor(i, raw + 1)) {
      sum += i;
    }

    findNumbers(i + 1);
  }

  function isHighestDivisor(num, j) {
    if (j >= num) return true;
    if (num % j === 0) return false;
    return isHighestDivisor(num, j + 1);
  }

  findNumbers(raw + 1);
}

Problem Link: Sum of N Practice Coding Problem

@sanchit_codes
plzz explain your logic.

findNumbers Function goes through numbers from raw + 1 up to raw * raw. It checks if each number i is divisible by raw and if raw is its biggest divisor using isHighestDivisor function. If both are true, it adds that number to sum. This keeps going until i exceeds raw * raw.

isHighestDivisor function checks recursively if there are any divisors of num between raw + 1 and num itself. If it finds a divisor larger than raw, it says false. If not, it says true.

@sanchit_codes
your logic will give tle for the given constraints .
U have to apply sieve to check for prime number .
and think of some logic that includes prime number to find the answer.

thanks for your help :smiley: