Skip to content

Instantly share code, notes, and snippets.

@jasonsperske
Last active December 15, 2015 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonsperske/5189806 to your computer and use it in GitHub Desktop.
Save jasonsperske/5189806 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.List;
public class PrimeFactorsOf {
public static void main(String ... args) {
System.out.println(primeFactorsOf(19252389595L));
}
static List<Long> primeFactorsOf(long val) {
long n = val;
List<Long> factors = new ArrayList<Long>();
for (long i = 2; i <= n / i; i++) {
while (n % i == 0) {
factors.add(i);
n /= i;
}
}
if (n > 1) {
factors.add(n);
}
return factors;
}
}
def primeFactorsOf(val):
n = val
factors = []
i = 2
while i <= (n / i):
while n % i == 0:
factors.append(i)
n /= i
i += 1
if n > 1:
factors.append(n)
return factors
if __name__=="__main__":
print primeFactorsOf(19252389595)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment