diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..0d09973 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Microsoft +ColumnLimit: 110 \ No newline at end of file diff --git a/ReciprocalSearch2.cpp b/ReciprocalSearch2.cpp index 0348cc3..135519b 100644 --- a/ReciprocalSearch2.cpp +++ b/ReciprocalSearch2.cpp @@ -1,12 +1,13 @@ -#include #include +#include -#pragma warning(disable:4146) +#pragma warning(disable : 4146) #include -#define min(a,b) (((a)<(b))?(a):(b)) +#define min(a, b) (((a) < (b)) ? (a) : (b)) -inline bool check(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10) { +inline bool check(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10) +{ int a[10]; a[0] = i1; @@ -17,7 +18,7 @@ inline bool check(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8 a[5] = i6; a[6] = i7; a[7] = i8; - a[8] = i9; + a[8] = i9; for (int k = 8; k >= 0; --k) { @@ -28,12 +29,14 @@ inline bool check(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8 a[9] = i10; mpz_class s1 = 1; - for (int k = 0; k < 10; ++k) { + for (int k = 0; k < 10; ++k) + { s1 *= a[k]; } mpz_class s2 = 0; - for (int k = 0; k < 10; ++k) { + for (int k = 0; k < 10; ++k) + { s2 += s1 / a[k]; } @@ -41,7 +44,8 @@ inline bool check(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8 } mpz_t q1, r1; -inline int ceil(const mpq_class& m) { +inline int ceil(const mpq_class &m) +{ mpz_tdiv_qr(q1, r1, m.get_num().get_mpz_t(), m.get_den().get_mpz_t()); if (mpz_cmp_si(q1, 100) > 0) return 100; @@ -53,7 +57,8 @@ inline int ceil(const mpq_class& m) { return ret; } -int main() { +int main() +{ const auto start = std::chrono::steady_clock::now(); int total = 0; @@ -67,66 +72,86 @@ int main() { mpq_class ii[101]; - for (int i = 1; i <= 100; i++) { + for (int i = 1; i <= 100; i++) + { mpz_class num(1); mpz_class den(i); ii[i] = mpq_class(num, den); } - for (int i1 = 2; i1 <= 10; i1++) { + for (int i1 = 2; i1 <= 10; i1++) + { const mpq_class m1 = 1 - ii[i1]; const int u2 = min(92, ceil(9 / m1)); - for (int i2 = i1 + 1; i2 <= u2; i2++) { + for (int i2 = i1 + 1; i2 <= u2; i2++) + { const mpq_class m2 = m1 - ii[i2]; const int u3 = min(93, ceil(8 / m2)); - for (int i3 = i2 + 1; i3 <= u3; i3++) { + for (int i3 = i2 + 1; i3 <= u3; i3++) + { const mpq_class m3 = m2 - ii[i3]; - if (m3 <= 0) continue; + if (m3 <= 0) + continue; const int u4 = min(94, ceil(7 / m3)); - for (int i4 = i3 + 1; i4 <= u4; i4++) { + for (int i4 = i3 + 1; i4 <= u4; i4++) + { const mpq_class m4 = m3 - ii[i4]; - if (m4 <= 0) continue; + if (m4 <= 0) + continue; const int u5 = min(95, ceil(6 / m4)); - for (int i5 = i4 + 1; i5 <= u5; i5++) { + for (int i5 = i4 + 1; i5 <= u5; i5++) + { const mpq_class m5 = m4 - ii[i5]; - if (m5 <= 0) continue; + if (m5 <= 0) + continue; const int u6 = min(96, ceil(5 / m5)); - for (int i6 = i5 + 1; i6 <= u6; i6++) { + for (int i6 = i5 + 1; i6 <= u6; i6++) + { const mpq_class m6 = m5 - ii[i6]; - if (m6 <= 0) continue; + if (m6 <= 0) + continue; const int u7 = min(97, ceil(4 / m6)); - for (int i7 = i6 + 1; i7 <= u7; i7++) { + for (int i7 = i6 + 1; i7 <= u7; i7++) + { const mpq_class m7 = m6 - ii[i7]; - if (m7 <= 0) continue; + if (m7 <= 0) + continue; const int u8 = min(98, ceil(3 / m7)); - for (int i8 = i7 + 1; i8 <= u8; i8++) { + for (int i8 = i7 + 1; i8 <= u8; i8++) + { const mpq_class m8 = m7 - ii[i8]; - if (m8 <= 0) continue; + if (m8 <= 0) + continue; const int u9 = min(99, ceil(2 / m8)); - for (int i9 = i8 + 1; i9 <= u9; i9++) { + for (int i9 = i8 + 1; i9 <= u9; i9++) + { const mpq_class m9 = m8 - ii[i9]; - if (m9 <= 0) continue; + if (m9 <= 0) + continue; const mpq_class last = 1 / m9; - mpz_tdiv_qr(q, r, last.get_num().get_mpz_t(), last.get_den().get_mpz_t()); - if (mpz_cmp_si(r, 0) != 0) continue; - if (mpz_cmp_si(q, 100) > 0) continue; + mpz_tdiv_qr(q, r, last.get_num().get_mpz_t(), + last.get_den().get_mpz_t()); + if (mpz_cmp_si(r, 0) != 0) + continue; + if (mpz_cmp_si(q, 100) > 0) + continue; const int i10 = mpz_get_si(q); - if (i10 <= i9) continue; + if (i10 <= i9) + continue; - if (check(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10)) { - ++total; - printf("%5d: %d %d %d %d %d %d %d %d %d %d\n", total, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10); - } + ++total; + printf("%5d: %d %d %d %d %d %d %d %d %d %d\n", total, i1, i2, i3, i4, + i5, i6, i7, i8, i9, i10); } } } @@ -144,5 +169,6 @@ int main() { mpz_clear(r1); const auto end = std::chrono::steady_clock::now(); - printf("%.3f seconds\n", std::chrono::duration_cast(end - start).count() / 1000.0); + printf("%.3f seconds\n", + std::chrono::duration_cast(end - start).count() / 1000.0); } \ No newline at end of file