Loading...
Loading...
Loading...
A teacher has n sweets and wants to share them equally in groups with none left over. Every factor of n is a possible group size. Print all factors of n in increasing order, and then how many there are.
Count: k, where k is the number of factors.Example 1
Input
12
Output
1 2 3 4 6 12 Count: 6
12 divides exactly by 1, 2, 3, 4, 6 and 12.
Example 2
Input
7
Output
1 7 Count: 2
A prime has exactly two factors.
Try the problem first. Open one hint at a time.
i is a factor when n % i == 0.
Try every i from 1 to n. Count the factors as you print them.
To avoid a space at the end, print a space before every factor except the first.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor