-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path_10699_CountTheFactors.java
42 lines (34 loc) · 1.02 KB
/
_10699_CountTheFactors.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package io.github.tahanima.uva;
import java.util.Scanner;
/**
* @author tahanima
*/
public class _10699_CountTheFactors {
static final int MAX = 1000001;
static final int[] countOfPrimeFactors = new int[MAX];
public static void computePrimeFactors() {
for (int i = 2; i < MAX; i++) {
if (countOfPrimeFactors[i] == 0) {
for (int j = i; j < MAX; j += i) {
countOfPrimeFactors[j]++;
}
}
}
}
public static void main(String[] args) {
computePrimeFactors();
Scanner scanner = new Scanner(System.in);
StringBuilder stringBuilder = new StringBuilder();
while (scanner.hasNext()) {
int n = scanner.nextInt();
if (n == 0) {
break;
}
stringBuilder.append(n)
.append(" : ")
.append(countOfPrimeFactors[n])
.append("\n");
}
System.out.print(stringBuilder);
}
}