-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheNumber.java
More file actions
51 lines (47 loc) · 1.6 KB
/
TheNumber.java
File metadata and controls
51 lines (47 loc) · 1.6 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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import org.apfloat.ApfloatRuntimeException;
import org.apfloat.Apint;
import org.apfloat.ApintMath;
public class TheNumber {
public static void main(String[] args) throws ApfloatRuntimeException, IOException {
Apint a = new Apint(2);
Apint swap = new Apint(0);
a = ApintMath.pow(a, 8589934591l);
a = a.subtract(new Apint(1));
System.out.println("Calculations done");
PrintWriter pls = null;
long size = a.size();
System.out.println(size);
System.out.println(size / 1000000);
//this records the last 1,000,000 digits to a txt and then cuts them off the end of the number
for (long i = 0; i <= size / 1000000; i++) {
pls = new PrintWriter("theNumber" + i + ".txt");
Apint modFactor = ApintMath.pow(new Apint(10), 1000000);
swap = a.mod(modFactor);
swap.writeTo(pls);
pls.flush();
System.out.println("swap " + i + " done");
a = a.divide(modFactor);
System.out.println("divide " + i + " done");
}
pls.close();
System.out.println("Temp files done");
PrintWriter pls2 = new PrintWriter("theNumber.txt");
//goes through all the temp txt's writes them to one final txt then deletes them
for (long i = size / 1000000; i >= 0; i--) {
File file = new File("theNumber" + i + ".txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
pls2.write(reader.readLine());
reader.close();
pls2.flush();
file.deleteOnExit();
System.out.println("File " + i + " deleted");
}
pls2.close();
System.out.println("Done");
}
}