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]
public static List<int> PrimeFactors(int n)
{
if (n == 1)
{
return null;
}
var list = new List<int>();
if (n % 2 == 0)
{
list.Add(2);
while (n % 2 == 0)
{
n /= 2;
}
}
for (int i = 3; i <= Math.Sqrt(n); i += 2)
{
if (n % i == 0)
{
list.Add(i);
while (n % i == 0)
{
n /= i;
}
}
}
if (n > 2)
list.Add(n);
return list;
}
public List<Integer> factorsOf(int n) {
ArrayList<Integer> factors = new ArrayList<>();
for (int d = 2; n > 1; d++)
for (; n % d == 0; n /= d)
factors.add(d);
return factors;
}
def primeFactors(n):
global factors
if(n==1):
return
elif((n%factors)== 0):
print(factors)
primeFactors(n//factors)
else:
factors+=1
primeFactors(n)
factors = 2
public static List<int> PrimeFactors(int n)
{
if (n == 1)
{
return null;
}
var list = new List<int>();
if (n % 2 == 0)
{
list.Add(2);
while (n % 2 == 0)
{
n /= 2;
}
}
for (int i = 3; i <= Math.Sqrt(n); i += 2)
{
if (n % i == 0)
{
list.Add(i);
while (n % i == 0)
{
n /= i;
}
}
}
if (n > 2)
list.Add(n);
return list;
}