-
Notifications
You must be signed in to change notification settings - Fork 31
/
example005a_pow_factors_of_p99.cpp
78 lines (64 loc) · 2.47 KB
/
example005a_pow_factors_of_p99.cpp
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
///////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2018 - 2024. //
// Distributed under the Boost Software License, //
// Version 1.0. (See accompanying file LICENSE_1_0.txt //
// or copy at http://www.boost.org/LICENSE_1_0.txt) //
///////////////////////////////////////////////////////////////////
#include <examples/example_uintwide_t.h>
#include <math/wide_integer/uintwide_t.h>
#if defined(WIDE_INTEGER_NAMESPACE)
auto WIDE_INTEGER_NAMESPACE::math::wide_integer::example005a_pow_factors_of_p99() -> bool
#else
auto ::math::wide_integer::example005a_pow_factors_of_p99() -> bool
#endif
{
#if defined(WIDE_INTEGER_NAMESPACE)
using uint384_t = WIDE_INTEGER_NAMESPACE::math::wide_integer::uintwide_t<static_cast<WIDE_INTEGER_NAMESPACE::math::wide_integer::size_t>(UINT32_C(384))>;
#else
using uint384_t = ::math::wide_integer::uintwide_t<static_cast<math::wide_integer::size_t>(UINT32_C(384))>;
#endif
const uint384_t c = (pow(uint384_t(10U), 99) - 1) / 9;
// Consider Table 9, page 410 of the classic work:
// H. Riesel, "Prime Numbers and Computer Methods of Factorization",
// Second Edition (Birkhaeuser, 1994). In that table, we find the
// prime factorization of P99 = (10^99 - 1) / 9. This example
// verifies the tabulated result.
// FactorInteger[(10^33 - 1)/9]
const uint384_t control_p33
{
uint384_t(3U)
* uint384_t(37U)
* uint384_t(67U)
* uint384_t(21649U)
* uint384_t(513239U)
* uint384_t("1344628210313298373")
};
// FactorInteger[(10^99 - 1)/9]
const uint384_t control_p99
{
control_p33
* uint384_t(3U)
* uint384_t(199U)
* uint384_t(397U)
* uint384_t(34849U)
* uint384_t(333667U)
* uint384_t("362853724342990469324766235474268869786311886053883")
};
const auto result_is_ok = (c == control_p99);
return result_is_ok;
}
// Enable this if you would like to activate this main() as a standalone example.
#if defined(WIDE_INTEGER_STANDALONE_EXAMPLE005A_POW_FACTORS_OF_P99)
#include <iomanip>
#include <iostream>
auto main() -> int
{
#if defined(WIDE_INTEGER_NAMESPACE)
const auto result_is_ok = WIDE_INTEGER_NAMESPACE::math::wide_integer::example005a_pow_factors_of_p99();
#else
const auto result_is_ok = ::math::wide_integer::example005a_pow_factors_of_p99();
#endif
std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;
return (result_is_ok ? 0 : -1);
}
#endif