Created
February 3, 2018 23:22
-
-
Save chermehdi/1673d7599274d416b077107e17f0da3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedHashMap; | |
import java.util.Map; | |
/** | |
* @author MaxHeap | |
*/ | |
public class Main { | |
public static Map<Long, Integer> factorize(long n) { | |
Map<Long, Integer> factors = new LinkedHashMap<>(); | |
for (long d = 2; n > 1; ) { | |
int power = 0; | |
while (n % d == 0) { | |
++power; | |
n /= d; | |
} | |
if (power > 0) { | |
factors.put(d, power); | |
} | |
++d; | |
if (d * d > n) { | |
d = n; | |
} | |
} | |
return factors; | |
} | |
public static void main(String[] args) { | |
System.out.println(factorize(10000056939L)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment