16 lines
342 B
Dart
16 lines
342 B
Dart
|
class PrimeFactors {
|
||
|
List<int> factors(int number) {
|
||
|
List<int> primeFactors = [];
|
||
|
int currentFactor = 2;
|
||
|
while (number != 1) {
|
||
|
if (number % currentFactor == 0) {
|
||
|
number ~/= currentFactor;
|
||
|
primeFactors.add(currentFactor);
|
||
|
} else {
|
||
|
currentFactor++;
|
||
|
}
|
||
|
}
|
||
|
return primeFactors;
|
||
|
}
|
||
|
}
|