-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2.cpp
More file actions
109 lines (75 loc) · 2.33 KB
/
Copy pathmain2.cpp
File metadata and controls
109 lines (75 loc) · 2.33 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
#define NDEBUG
#include <iostream>
#include <chrono>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/multiprecision/float128.hpp>
#include <boost/multiprecision/mpfr.hpp>
#include <immintrin.h>
namespace mp = boost::multiprecision;
void taxi_cab(mp::uint128_t tc)
{
mp::uint128_t raja = (mp::cbrt(tc.convert_to<mp::float128>()) + 0.5).convert_to<mp::uint128_t>();
std::cout << raja << "\n";
mp::uint128_t temp1 = 0, temp2 = 0, temp3 =0, temp4 = 0;
mp::uint128_t i = 0;
mp::uint128_t j = 0;
for ( i = 1 ; i < raja ; i+= 4 )
{
mp::uint128_t t1 = tc - i*i*i;
mp::uint128_t i2 = i+1;
mp::uint128_t t2 = tc - i2*i2*i2;
mp::uint128_t i3 = i+2;
mp::uint128_t t3 = tc - i3*i3*i3;
mp::uint128_t i4 = i + 3;
mp::uint128_t t4 = tc - i4*i4*i4;
__m256d v1 = {t1.convert_to<double>(),
t2.convert_to<double>(),
t3.convert_to<double>(),
t4.convert_to<double>()};
//__m256d v2 =_mm256_cbrt_pd(v1);
__m256d v2 = {std::cbrt(v1[0]), std::cbrt(v1[1]), std::cbrt(v1[2]), std::cbrt(v1[3])};
j = mp::uint128_t(std::round(v2[0]));
if (j*j*j == t1)
{
if (i == temp1)
break;
std::cout << i << " " << j << "\n";
temp1 = j;
}
j = mp::uint128_t(std::round(v2[1]));
if (j*j*j == t2)
{
if (i2 == temp2)
break;
std::cout << i2 << " " << j << "\n";
temp2 = j;
}
j = mp::uint128_t(std::round(v2[2]));
if (j*j*j == t3)
{
if (i3 == temp3)
break;
std::cout << i3 << " " << j << "\n";
temp3 = j;
}
j = mp::uint128_t(std::round(v2[3]));
if (j*j*j == t4)
{
if (i4 == temp4)
break;
std::cout << i4 << " " << j << "\n";
temp4 = j;
}
}
}
int main()
{
auto t0 = std::chrono::steady_clock::now();
taxi_cab(mp::uint128_t("24153319581254312065344"));
auto t1 = std::chrono::steady_clock::now();
std::chrono::duration<double> dur = t1 - t0;
std::cout << dur.count() << "\n";
return 0;
}