-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactor.java
More file actions
59 lines (56 loc) · 1.62 KB
/
Factor.java
File metadata and controls
59 lines (56 loc) · 1.62 KB
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
import java.io.*;
import java.lang.Process;
import java.lang.ProcessBuilder;
import java.lang.ProcessBuilder.Redirect;
import java.util.*;
public class Factor
{
public static void main(String[] args) throws IOException, InterruptedException
{
int numChild = 1;
int total = 600000;
// Spawn children processes
for (int i = 0; i < numChild; i++)
{
ProcessBuilder pb = new ProcessBuilder("java", "FactorChild", String.valueOf(i));
pb.redirectOutput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
Process process = pb.start();
}
// Wait for children to finish
for (int i = 0; i < numChild; i++)
{
Process process = Runtime.getRuntime().exec("wait");
process.waitFor();
}
System.out.println("All Children Done: " + numChild);
}
}
class FactorChild
{
public static void main(String[] args)
{
int begin = 0;
int end = 0;
int id = Integer.parseInt(args[0]);
int range = 600000 / 1;
begin = id * range;
end = begin + range;
int start_s = (int) System.currentTimeMillis();
int val, i;
for (val = begin; val < end; val++)
{
for (i = 2; i <= val / 2; i++)
{
if (val % i == 0) break;
}
if (i > val / 2)
{
System.out.println("F:" + val);
}
}
int stop_s = (int) System.currentTimeMillis();
System.err.println("time: " + (stop_s - start_s));
System.exit(0);
}
}