-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDIVFACT.java
135 lines (95 loc) · 2.87 KB
/
DIVFACT.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
* Created by poplig on 8/15/15.
*/
public class Main {
private static final int MAX_NUMBER = 50000;
private static int[] primeNumbers = new int[50000];
private static int TOTAL_PRIME_NUMBERS = 0;
private static int MOD = 1000000007;
Main() {
}
public static void main(String[] args) {
prepareSieve();
InputReader inputReader = new InputReader(System.in);
int t = inputReader.nextInt();
while(t-->0) {
int n = inputReader.nextInt();
// calculate the number of prime number factors.
long ans = 1;
for(int i = 0; primeNumbers[i] <= n ; ++i) {
int temp = primeNumbers[i];
int count = 0;
while (n / temp >= 1) {
count += n / temp;
temp = temp * primeNumbers[i];
}
if(count == 0 ) {
System.out.println(temp + " " + primeNumbers[i]);
}
ans = (ans * (count + 1)) % MOD;
}
System.out.println(ans);
}
}
// prepare sieve
public static void prepareSieve() {
boolean[] sieve = new boolean[50000];
for (int i = 0; i < MAX_NUMBER; ++i) {
sieve[i] = true;
}
for (int i = 2; i < 300; ++i) {
if (sieve[i]) {
for (int j = 2; i * j < MAX_NUMBER; ++j) {
sieve[i * j] = false;
}
}
}
// store the prime numbers.
for (int i = 2; i < MAX_NUMBER; ++i) {
if (sieve[i]) {
primeNumbers[TOTAL_PRIME_NUMBERS++] = i;
}
}
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = "";
try {
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}