-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_test.cpp
More file actions
118 lines (106 loc) · 3.9 KB
/
full_test.cpp
File metadata and controls
118 lines (106 loc) · 3.9 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
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
/*
*务必-O2或者release
*/
#include "integer.h"
#include <chrono>
#include <iomanip>
#include <sstream>
using namespace std;
using namespace chrono;
string format_time(double ms) {
int sec = (int)(ms / 1000);
int msec = (int)ms % 1000;
stringstream ss;
ss << sec << ".";
if (msec < 10) ss << "00";
else if (msec < 100) ss << "0";
ss << msec << " s";
return ss.str();
}
int main() {
cout << "=====================================\n";
cout << " integer.h 测试结果\n";
cout << "=====================================\n\n";
auto total_start = high_resolution_clock::now();
double ms;
// 1. 计算 a = 1000000!
auto t1 = high_resolution_clock::now();
integer a = fac(1000000);
auto t2 = high_resolution_clock::now();
ms = duration_cast<microseconds>(t2 - t1).count() / 1000.0;
cout << "1. a = 1000000! = ";
a.print();
cout << " (" << format_time(ms) << ")\n\n";
// 2. 计算 b = C(5000000, 2500000)
t1 = high_resolution_clock::now();
integer b = C(5000000, 2500000);
t2 = high_resolution_clock::now();
ms = duration_cast<microseconds>(t2 - t1).count() / 1000.0;
cout << "2. b =C(5000000, 2500000) = ";
b.print();
cout << " (" << format_time(ms) << ")\n\n";
// 3. 计算 c = a / b
t1 = high_resolution_clock::now();
integer r;
integer c = a.divide(b, r);
t2 = high_resolution_clock::now();
ms = duration_cast<microseconds>(t2 - t1).count() / 1000.0;
cout << "3. c = a / b = ";
c.print();
cout << " (" << format_time(ms) << ")\n\n";
// 4. 计算 d = sqroot(a)
t1 = high_resolution_clock::now();
integer d = sqroot(a);
t2 = high_resolution_clock::now();
ms = duration_cast<microseconds>(t2 - t1).count() / 1000.0;
cout << "4. d = sqroot(a) = ";
d.print();
cout << " (" << format_time(ms) << ")\n\n";
// 5. 计算 e = gcd(100000!, 10^N)
t1 = high_resolution_clock::now();
integer f = fac(100000);
integer g_shift = integer(1).shift(f.num.size());
integer e = gcd(f, g_shift);
t2 = high_resolution_clock::now();
ms = duration_cast<microseconds>(t2 - t1).count() / 1000.0;
cout << "5. e = gcd(100000!, 10^N) = ";
e.print();
cout << " (" << format_time(ms) << ")\n\n";
// 6. 计算 g = power(300!, 400!, 500!)
t1 = high_resolution_clock::now();
integer base = fac(300);
integer exp = fac(400);
integer mod = fac(500);
integer g = power(base, exp, mod);
t2 = high_resolution_clock::now();
ms = duration_cast<microseconds>(t2 - t1).count() / 1000.0;
cout << "6. g = power(300!, 400!, 500!) = ";
g.print();
cout << " (" << format_time(ms) << ")\n\n";
// 7. 找出 n! + 1 是质数的 n
t1 = high_resolution_clock::now();
cout << "7. n! + 1 是质数的 n (1~300)miller+lucas: ";
integer fact = 1;
for (int n = 1; n <= 300; n++) {
fact = fact * integer(n);
if (isprime(fact + 1)) {
cout << n << " ";
}
}
t2 = high_resolution_clock::now();
ms = duration_cast<microseconds>(t2 - t1).count() / 1000.0;
cout << "\n (" << format_time(ms) << ")\n\n";
// 8. 费马数 F7 的质因子
t1 = high_resolution_clock::now();
cout << "8. euler phi(F7 = 2^128 + 1)=";
euler(power(2, 128) + 1).print();
t2 = high_resolution_clock::now();
ms = duration_cast<microseconds>(t2 - t1).count() / 1000.0;
cout << " (" << format_time(ms) << ")\n\n";
auto total_end = high_resolution_clock::now();
ms = duration_cast<microseconds>(total_end - total_start).count() / 1000.0;
cout << "=====================================\n";
cout << "总时间: " << format_time(ms) << "\n";
cout << "=====================================\n";
return 0;
}