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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| #include <iostream>
template <uint32_t uPower, int var=0>
struct Power2 { };
template <uint32_t uPower>
struct Power2<uPower, 0> {
static const uint64_t t256_a = 2*Power2<uPower-1, 1>::t256_a;
static const uint64_t t256_b = Power2<uPower-1, 1>::t256_b;
static const uint64_t t256_c = Power2<uPower-1, 1>::t256_c;
static const uint64_t t256_d = Power2<uPower-1, 1>::t256_d;
static const uint64_t t128_a = 2*Power2<uPower-1, 1>::t128_a;
static const uint64_t t128_b = Power2<uPower-1, 1>::t128_b;
static const uint32_t t32 = (uint32_t)(t256_a*t256_b*t256_c*t256_d);
static const uint64_t t64 = t256_a*t256_b*t256_c*t256_d;
};
template <uint32_t uPower>
struct Power2<uPower, 1> {
static const uint64_t t256_a = Power2<uPower-1, 2>::t256_a;
static const uint64_t t256_b = 2*Power2<uPower-1, 2>::t256_b;
static const uint64_t t256_c = Power2<uPower-1, 2>::t256_c;
static const uint64_t t256_d = Power2<uPower-1, 2>::t256_d;
static const uint64_t t128_a = Power2<uPower-1, 2>::t128_a;
static const uint64_t t128_b = 2*Power2<uPower-1, 2>::t128_b;
static const uint32_t t32 = (uint32_t)(t256_a*t256_b*t256_c*t256_d);
static const uint64_t t64 = t256_a*t256_b*t256_c*t256_d;
};
template <uint32_t uPower>
struct Power2<uPower, 2> {
static const uint64_t t256_a = Power2<uPower-1, 3>::t256_a;
static const uint64_t t256_b = Power2<uPower-1, 3>::t256_b;
static const uint64_t t256_c = 2*Power2<uPower-1, 3>::t256_c;
static const uint64_t t256_d = Power2<uPower-1, 3>::t256_d;
static const uint64_t t128_a = 2*Power2<uPower-1, 3>::t128_a;
static const uint64_t t128_b = Power2<uPower-1, 3>::t128_b;
static const uint32_t t32 = (uint32_t)(t256_a*t256_b*t256_c*t256_d);
static const uint64_t t64 = t256_a*t256_b*t256_c*t256_d;
};
template <uint32_t uPower>
struct Power2<uPower, 3> {
static const uint64_t t256_a = Power2<uPower-1, 0>::t256_a;
static const uint64_t t256_b = Power2<uPower-1, 0>::t256_b;
static const uint64_t t256_c = Power2<uPower-1, 0>::t256_c;
static const uint64_t t256_d = 2*Power2<uPower-1, 0>::t256_d;
static const uint64_t t128_a = Power2<uPower-1, 0>::t128_a;
static const uint64_t t128_b = 2*Power2<uPower-1, 0>::t128_b;
static const uint32_t t32 = (uint32_t)(t256_a*t256_b*t256_c*t256_d);
static const uint64_t t64 = t256_a*t256_b*t256_c*t256_d;
};
template <>
struct Power2< 0, 0 >
{
static const uint64_t t256_a = 1;
static const uint64_t t256_b = 1;
static const uint64_t t256_c = 1;
static const uint64_t t256_d = 1;
static const uint64_t t128_a = 1;
static const uint64_t t128_b = 1;
static const uint32_t t32 = (uint32_t)(t256_a*t256_b*t256_c*t256_d);
static const uint64_t t64 = t256_a*t256_b*t256_c*t256_d;
};
template <>
struct Power2< 0, 1 >
{
static const uint64_t t256_a = 1;
static const uint64_t t256_b = 1;
static const uint64_t t256_c = 1;
static const uint64_t t256_d = 1;
static const uint64_t t128_a = 1;
static const uint64_t t128_b = 1;
static const uint32_t t32 = (uint32_t)(t256_a*t256_b*t256_c*t256_d);
static const uint64_t t64 = t256_a*t256_b*t256_c*t256_d;
};
template <>
struct Power2< 0, 2 >
{
static const uint64_t t256_a = 1;
static const uint64_t t256_b = 1;
static const uint64_t t256_c = 1;
static const uint64_t t256_d = 1;
static const uint64_t t128_a = 1;
static const uint64_t t128_b = 1;
static const uint32_t t32 = (uint32_t)(t256_a*t256_b*t256_c*t256_d);
static const uint64_t t64 = t256_a*t256_b*t256_c*t256_d;
};
template <>
struct Power2< 0, 3 >
{
static const uint64_t t256_a = 1;
static const uint64_t t256_b = 1;
static const uint64_t t256_c = 1;
static const uint64_t t256_d = 1;
static const uint64_t t128_a = 1;
static const uint64_t t128_b = 1;
static const uint32_t t32 = (uint32_t)(t256_a*t256_b*t256_c*t256_d);
static const uint64_t t64 = t256_a*t256_b*t256_c*t256_d;
};
int main(int argc, char **argv) {
uint64_t p256_a = Power2<200>::t256_a;
uint64_t p256_b = Power2<200>::t256_b;
uint64_t p256_c = Power2<200>::t256_c;
uint64_t p256_d = Power2<200>::t256_d;
uint64_t p128_a = Power2<100>::t128_a;
uint64_t p128_b = Power2<100>::t128_b;
uint64_t p50 = Power2<50>::t64;
uint32_t p30 = Power2<30>::t32;
std::cout << "2^200 = " << p256_a << "*" << p256_b << "*" << p256_c << "*" << p256_d << "\n";
std::cout << "2^100 = " << p128_a << "*" << p128_b << "\n";
std::cout << "2^50 = " << p50 << "\n";
std::cout << "2^30 = " << p30 << "\n";
return 0;
} |
Partager