Skip to main content

Jagged Number

A k-rough or k-jagged number is a number whose smallest prime factor is greater than or equal to the number ‘k’. Given numbers ‘n’ and ‘k’ as input, we are required to find whether ‘n; is a k-rough number or not.



function jagged(n, k)
{
  var p = seive(n);
  var prime = [];
  for(var i = 2; i < n; i++)
  if(p[i] === 1) prime.push(i);
  var min_pf = n;

  for(var i = 0; i < prime.length; i++)
      if(n % prime[i] == 0) min_pf = prime[i];

  return (min_pf >= k);
}