Answers for "how to find factors of a number"

1

what are factors in math

If you don't remember, factors are numbers that when divided, does not leave a remainder. For example, the factors of 8 are: 1, 2, 4, 8 because when you divide 8 by 4, you get two. It also goes the same for others.
Posted by: Guest on October-04-2021
1

How could you find all prime factors of a number?

function primeFactors(n){
  var factors = [], 
      divisor = 2;
  
  while(n>2){
    if(n % divisor == 0){
       factors.push(divisor); 
       n= n/ divisor;
    }
    else{
      divisor++;
    }     
  }
  return factors;
}

> primeFactors(69);
  = [3, 23]
Posted by: Guest on May-21-2021
0

Find the prime factors of a number

>>> for n in range(2, 10):
...     for x in range(2, n):
...         if n % x == 0:
...             print(n, 'equals', x, '*', n//x)
...             break
...     else:
...         # loop fell through without finding a factor
...         print(n, 'is a prime number')
...
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3
Posted by: Guest on September-07-2021

Code answers related to "how to find factors of a number"

Browse Popular Code Answers by Language