Loading...
Loading...
Loading...
Every whole number above 1 can be written as a product of primes, like 360 = 2 x 2 x 2 x 3 x 3 x 5. Read n and print its prime factors from smallest to largest, joined by x .
x .nextLong().Example 1
Input
360
Output
2 x 2 x 2 x 3 x 3 x 5
360 = 2 x 2 x 2 x 3 x 3 x 5.
Example 2
Input
97
Output
97
A prime is its own only factor.
Try the problem first. Open one hint at a time.
Try divisors i = 2, 3, 4, ... While i divides n, print i and divide n by i.
Composite i like 4 never divide n by then, because their prime parts were already divided out.
Stop when i * i > n. Whatever is left above 1 is one last prime factor.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor