From 8f9c6e307f329b6df1dd1b3484820fef6ceb7461 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 13 Apr 2022 16:50:59 +0800 Subject: [PATCH] =?UTF-8?q?202.=20=E6=9C=80=E5=B9=B8=E8=BF=90=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/13373247/ --- AcWing/202/202.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++ AcWing/202/data/3.ans | 3 +++ AcWing/202/data/3.in | 3 +++ 3 files changed, 60 insertions(+) create mode 100644 AcWing/202/202.cpp create mode 100644 AcWing/202/data/3.ans create mode 100644 AcWing/202/data/3.in diff --git a/AcWing/202/202.cpp b/AcWing/202/202.cpp new file mode 100644 index 00000000..084f335e --- /dev/null +++ b/AcWing/202/202.cpp @@ -0,0 +1,54 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +int t; +long long l; + +long long euler(long long x) { + long long r = x; + for (long long i = 2; i * i <= x; i++) { + if (x % i == 0) { + r = r / i * (i - 1); + while (x % i == 0) x /= i; + } + } + if (x > 1) r = r / x * (x - 1); + return r; +} + +long long binpow(__int128 a, long long b, long long m) { + a %= m; + __int128 res = 1; + while (b > 0) { + if (b & 1) res = res * a % m; + a = a * a % m; + b >>= 1; + } + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + + while (cin >> l, l) { + long long d = std::__gcd(l, 8ll); + long long n = euler(9ll * l / d); + long long ans = std::numeric_limits::max(); + + for (long long i = 1; i * i <= n; i++) { + if (n % i == 0) { + if (binpow(10, i, 9ll * l / d) == 1) ans = std::min(ans, i); + if (binpow(10, n / i, 9ll * l / d) == 1) ans = std::min(ans, n / i); + } + } + + cout << "Case " << ++t << ": " << (ans == std::numeric_limits::max() ? 0 : ans) << endl; + } + + return 0; +} diff --git a/AcWing/202/data/3.ans b/AcWing/202/data/3.ans new file mode 100644 index 00000000..3958e6d6 --- /dev/null +++ b/AcWing/202/data/3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c5a2734e5a6c3a45f348713f8019fa4c2b3555667044ad719b9a90ab292651ec +size 53 diff --git a/AcWing/202/data/3.in b/AcWing/202/data/3.in new file mode 100644 index 00000000..a04c97d1 --- /dev/null +++ b/AcWing/202/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e39320a6bf2989bbab84f484275b6a3907869b917453eca1e6614520cd816a7 +size 35