結果
| 問題 |
No.3081 Make Palindromic Multiple
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-01 09:43:00 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 30,027 bytes |
| コンパイル時間 | 4,250 ms |
| コンパイル使用メモリ | 245,984 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-04-01 09:43:08 |
| 合計ジャッジ時間 | 6,946 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 54 |
ソースコード
#include <utility>
#include <cassert>
#include <map>
#include <chrono>
#include <numeric>
#include <unordered_map>
#include <set>
#include <optional>
#include <bitset>
#include <unordered_set>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <ostream>
#include <functional>
#include <type_traits>
#include <random>
#include <deque>
#include <istream>
#include <algorithm>
#include <array>
#include <queue>
#include <iomanip>
#include <iterator>
#include <stack>
#ifndef KK2_TEMPLATE_PROCON_HPP
#define KK2_TEMPLATE_PROCON_HPP 1
#ifndef KK2_TEMPLATE_CONSTANT_HPP
#define KK2_TEMPLATE_CONSTANT_HPP 1
#ifndef KK2_TEMPLATE_TYPE_ALIAS_HPP
#define KK2_TEMPLATE_TYPE_ALIAS_HPP 1
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
using pi = std::pair<int, int>;
using pl = std::pair<i64, i64>;
using pil = std::pair<int, i64>;
using pli = std::pair<i64, int>;
template <class T> using vc = std::vector<T>;
template <class T> using vvc = std::vector<vc<T>>;
template <class T> using vvvc = std::vector<vvc<T>>;
template <class T> using vvvvc = std::vector<vvvc<T>>;
template <class T> using pq = std::priority_queue<T>;
template <class T> using pqi = std::priority_queue<T, std::vector<T>, std::greater<T>>;
#endif // KK2_TEMPLATE_TYPE_ALIAS_HPP
template <class T> constexpr T infty = 0;
template <> constexpr int infty<int> = (1 << 30) - 123;
template <> constexpr i64 infty<i64> = (1ll << 62) - (1ll << 31);
template <> constexpr i128 infty<i128> = (i128(1) << 126) - (i128(1) << 63);
template <> constexpr u32 infty<u32> = infty<int>;
template <> constexpr u64 infty<u64> = infty<i64>;
template <> constexpr u128 infty<u128> = infty<i128>;
template <> constexpr double infty<double> = infty<i64>;
template <> constexpr long double infty<long double> = infty<i64>;
constexpr int mod = 998244353;
constexpr int modu = 1e9 + 7;
constexpr long double PI = 3.14159265358979323846;
#endif // KK2_TEMPLATE_CONSTANT_HPP
#ifndef KK2_TEMPLATE_FUNCTION_UTIL_HPP
#define KK2_TEMPLATE_FUNCTION_UTIL_HPP 1
namespace kk2 {
template <class T, class... Sizes> auto make_vector(int first, Sizes... sizes) {
if constexpr (sizeof...(sizes) == 0) {
return std::vector<T>(first);
} else {
return std::vector<decltype(make_vector<T>(sizes...))>(first, make_vector<T>(sizes...));
}
}
template <class T, class U> void fill_all(std::vector<T> &v, const U &x) {
std::fill(std::begin(v), std::end(v), T(x));
}
template <class T, class U> void fill_all(std::vector<std::vector<T>> &v, const U &x) {
for (auto &u : v) fill_all(u, x);
}
template <class C> int mysize(const C &c) {
return c.size();
}
// T: comutative monoid
template <class T, class U> U all_sum(const std::vector<T> &v, U init, U = U()) {
U res = init;
for (const auto &x : v) res += x;
return res;
}
template <class T, class U> U all_sum(const std::vector<std::vector<T>> &v, U init, U unit = U()) {
U res = init;
for (const auto &u : v) res += all_sum(u, unit, unit);
return res;
}
// T: commutative monoid, F: (U, T) -> U
template <class T, class U, class F> U all_prod(const std::vector<T> &v, U init, const F &f, U = U()) {
U res = init;
for (const auto &x : v) res = f(res, x);
return res;
}
template <class T, class U, class F>
U all_prod(const std::vector<std::vector<T>> &v, U init, const F &f, U unit) {
U res = init;
for (const auto &u : v) res = f(res, all_prod(u, unit, f, unit));
return res;
}
template <class T> T all_min(const std::vector<T> &v) {
if (v.empty()) return T();
T res = v[0];
for (const auto &x : v) res = res > x ? x : res;
return res;
}
template <class T>
T all_min(const std::vector<std::vector<T>> &v) {
T res{};
bool first = true;
for (const auto &u : v) {
if (u.empty()) continue;
if (first) {
res = all_min(u);
first = false;
} else {
T tmp = all_min(u);
res = res > tmp ? tmp : res;
}
}
return res;
}
template <class T> T all_max(const std::vector<T> &v) {
if (v.empty()) return T();
T res = v[0];
for (const auto &x : v) res = res < x ? x : res;
return res;
}
template <class T>
T all_max(const std::vector<std::vector<T>> &v) {
T res{};
bool first = true;
for (const auto &u : v) {
if (u.empty()) continue;
if (first) {
res = all_max(u);
first = false;
} else {
T tmp = all_max(u);
res = res < tmp ? tmp : res;
}
}
return res;
}
} // namespace kk2
#endif // KK2_TEMPLATE_FUNCTION_UTIL_HPP
#ifndef KK2_TEMPLATE_IO_UTIL_HPP
#define KK2_TEMPLATE_IO_UTIL_HPP 1
#ifndef KK2_TYPE_TRAITS_TYPE_TRAITS_HPP
#define KK2_TYPE_TRAITS_TYPE_TRAITS_HPP 1
namespace kk2 {
#ifndef _MSC_VER
template <typename T>
using is_signed_int128 = typename std::conditional<std::is_same<T, __int128_t>::value
or std::is_same<T, __int128>::value,
std::true_type,
std::false_type>::type;
template <typename T>
using is_unsigned_int128 =
typename std::conditional<std::is_same<T, __uint128_t>::value
or std::is_same<T, unsigned __int128>::value,
std::true_type,
std::false_type>::type;
template <typename T>
using is_integral =
typename std::conditional<std::is_integral<T>::value or is_signed_int128<T>::value
or is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <typename T>
using is_signed = typename std::conditional<std::is_signed<T>::value or is_signed_int128<T>::value,
std::true_type,
std::false_type>::type;
template <typename T>
using is_unsigned =
typename std::conditional<std::is_unsigned<T>::value or is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <typename T>
using make_unsigned_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value, __uint128_t, unsigned __int128>;
template <typename T>
using to_unsigned =
typename std::conditional<is_signed_int128<T>::value,
make_unsigned_int128<T>,
typename std::conditional<std::is_signed<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type>::type;
#else
template <typename T> using is_integral = std::enable_if_t<std::is_integral<T>::value>;
template <typename T> using is_signed = std::enable_if_t<std::is_signed<T>::value>;
template <typename T> using is_unsigned = std::enable_if_t<std::is_unsigned<T>::value>;
template <typename T> using to_unsigned = std::make_unsigned<T>;
#endif // _MSC_VER
template <typename T> using is_integral_t = std::enable_if_t<is_integral<T>::value>;
template <typename T> using is_signed_t = std::enable_if_t<is_signed<T>::value>;
template <typename T> using is_unsigned_t = std::enable_if_t<is_unsigned<T>::value>;
template <typename T>
using is_function_pointer =
typename std::conditional<std::is_pointer_v<T> && std::is_function_v<std::remove_pointer_t<T>>,
std::true_type,
std::false_type>::type;
template <typename T, std::enable_if_t<is_function_pointer<T>::value> * = nullptr>
struct is_two_args_function_pointer : std::false_type {};
template <typename R, typename T1, typename T2>
struct is_two_args_function_pointer<R (*)(T1, T2)> : std::true_type {};
template <typename T>
using is_two_args_function_pointer_t = std::enable_if_t<is_two_args_function_pointer<T>::value>;
namespace type_traits {
struct istream_tag {};
struct ostream_tag {};
} // namespace type_traits
template <typename T>
using is_standard_istream = typename std::conditional<std::is_same<T, std::istream>::value
|| std::is_same<T, std::ifstream>::value,
std::true_type,
std::false_type>::type;
template <typename T>
using is_standard_ostream = typename std::conditional<std::is_same<T, std::ostream>::value
|| std::is_same<T, std::ofstream>::value,
std::true_type,
std::false_type>::type;
template <typename T> using is_user_defined_istream = std::is_base_of<type_traits::istream_tag, T>;
template <typename T> using is_user_defined_ostream = std::is_base_of<type_traits::ostream_tag, T>;
template <typename T>
using is_istream =
typename std::conditional<is_standard_istream<T>::value || is_user_defined_istream<T>::value,
std::true_type,
std::false_type>::type;
template <typename T>
using is_ostream =
typename std::conditional<is_standard_ostream<T>::value || is_user_defined_ostream<T>::value,
std::true_type,
std::false_type>::type;
template <typename T> using is_istream_t = std::enable_if_t<is_istream<T>::value>;
template <typename T> using is_ostream_t = std::enable_if_t<is_ostream<T>::value>;
} // namespace kk2
#endif // KK2_TYPE_TRAITS_TYPE_TRAITS_HPP
// なんかoj verifyはプロトタイプ宣言が落ちる
namespace impl {
struct read {
template <class IStream, class T>
inline static void all_read(IStream &is, T &x) {
is >> x;
}
template <class IStream, class T, class U>
inline static void all_read(IStream &is, std::pair<T, U> &p) {
all_read(is, p.first);
all_read(is, p.second);
}
template <class IStream, class T>
inline static void all_read(IStream &is, std::vector<T> &v) {
for (T &x : v) all_read(is, x);
}
template <class IStream, class T, size_t F>
inline static void all_read(IStream &is, std::array<T, F> &a) {
for (T &x : a) all_read(is, x);
}
};
struct write {
template <class OStream, class T>
inline static void all_write(OStream &os, const T &x) {
os << x;
}
template <class OStream, class T, class U>
inline static void all_write(OStream &os, const std::pair<T, U> &p) {
all_write(os, p.first);
all_write(os, ' ');
all_write(os, p.second);
}
template <class OStream, class T>
inline static void all_write(OStream &os, const std::vector<T> &v) {
for (int i = 0; i < (int)v.size(); ++i) {
if (i) all_write(os, ' ');
all_write(os, v[i]);
}
}
template <class OStream, class T, size_t F>
inline static void all_write(OStream &os, const std::array<T, F> &a) {
for (int i = 0; i < (int)F; ++i) {
if (i) all_write(os, ' ');
all_write(os, a[i]);
}
}
};
} // namespace impl
template <class IStream, class T, class U, kk2::is_istream_t<IStream> * = nullptr>
IStream &operator>>(IStream &is, std::pair<T, U> &p) {
impl::read::all_read(is, p);
return is;
}
template <class IStream, class T, kk2::is_istream_t<IStream> * = nullptr>
IStream &operator>>(IStream &is, std::vector<T> &v) {
impl::read::all_read(is, v);
return is;
}
template <class IStream, class T, size_t F, kk2::is_istream_t<IStream> * = nullptr>
IStream &operator>>(IStream &is, std::array<T, F> &a) {
impl::read::all_read(is, a);
return is;
}
template <class OStream, class T, class U, kk2::is_ostream_t<OStream> * = nullptr>
OStream &operator<<(OStream &os, const std::pair<T, U> &p) {
impl::write::all_write(os, p);
return os;
}
template <class OStream, class T, kk2::is_ostream_t<OStream> * = nullptr>
OStream &operator<<(OStream &os, const std::vector<T> &v) {
impl::write::all_write(os, v);
return os;
}
template <class OStream, class T, size_t F, kk2::is_ostream_t<OStream> * = nullptr>
OStream &operator<<(OStream &os, const std::array<T, F> &a) {
impl::write::all_write(os, a);
return os;
}
#endif // KK2_TEMPLATE_IO_UTIL_HPP
#ifndef KK2_TEMPLATE_MACROS_HPP
#define KK2_TEMPLATE_MACROS_HPP 1
#define rep1(a) for (long long _ = 0; _ < (long long)(a); ++_)
#define rep2(i, a) for (long long i = 0; i < (long long)(a); ++i)
#define rep3(i, a, b) for (long long i = (a); i < (long long)(b); ++i)
#define repi2(i, a) for (long long i = (a) - 1; i >= 0; --i)
#define repi3(i, a, b) for (long long i = (a) - 1; i >= (long long)(b); --i)
#define overload3(a, b, c, d, ...) d
#define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define repi(...) overload3(__VA_ARGS__, repi3, repi2, rep1)(__VA_ARGS__)
#define fi first
#define se second
#define all(p) p.begin(), p.end()
#endif // KK2_TEMPLATE_MACROS_HPP
struct FastIOSetUp {
FastIOSetUp() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} fast_io_set_up;
auto &kin = std::cin;
auto &kout = std::cout;
auto (*kendl)(std::ostream &) = std::endl<char, std::char_traits<char>>;
void Yes(bool b = 1) {
kout << (b ? "Yes\n" : "No\n");
}
void No(bool b = 1) {
kout << (b ? "No\n" : "Yes\n");
}
void YES(bool b = 1) {
kout << (b ? "YES\n" : "NO\n");
}
void NO(bool b = 1) {
kout << (b ? "NO\n" : "YES\n");
}
void yes(bool b = 1) {
kout << (b ? "yes\n" : "no\n");
}
void no(bool b = 1) {
kout << (b ? "no\n" : "yes\n");
}
template <class T, class S> inline bool chmax(T &a, const S &b) {
return (a < b ? a = b, 1 : 0);
}
template <class T, class S> inline bool chmin(T &a, const S &b) {
return (a > b ? a = b, 1 : 0);
}
std::istream &operator>>(std::istream &is, u128 &x) {
std::string s;
is >> s;
x = 0;
for (char c : s) {
assert('0' <= c && c <= '9');
x = x * 10 + c - '0';
}
return is;
}
std::istream &operator>>(std::istream &is, i128 &x) {
std::string s;
is >> s;
bool neg = s[0] == '-';
x = 0;
for (int i = neg; i < (int)s.size(); i++) {
assert('0' <= s[i] && s[i] <= '9');
x = x * 10 + s[i] - '0';
}
if (neg) x = -x;
return is;
}
std::ostream &operator<<(std::ostream &os, u128 x) {
if (x == 0) return os << '0';
std::string s;
while (x) {
s.push_back('0' + x % 10);
x /= 10;
}
std::reverse(s.begin(), s.end());
return os << s;
}
std::ostream &operator<<(std::ostream &os, i128 x) {
if (x == 0) return os << '0';
if (x < 0) {
os << '-';
x = -x;
}
std::string s;
while (x) {
s.push_back('0' + x % 10);
x /= 10;
}
std::reverse(s.begin(), s.end());
return os << s;
}
#endif // KK2_TEMPLATE_PROCON_HPP
// #include <kk2/template/debug.hpp>
#ifndef KK2_MATH_MAX_DIVISION_TIMES_HPP
#define KK2_MATH_MAX_DIVISION_TIMES_HPP 1
namespace kk2 {
template <class T, class U>
int max_division_times(T a, U b) {
int res = 0;
while (a % b == 0) a /= b, res++;
return res;
}
template <class T, class U>
int divide_max_times(T &a, U b) {
int res = 0;
while (a % b == 0) a /= b, res++;
return res;
}
} // namespace kk2
#endif // KK2_MATH_MAX_DIVISION_TIMES_HPP
#ifndef KK2_MATH_CONVERT_BASE_HPP
#define KK2_MATH_CONVERT_BASE_HPP 1
namespace kk2 {
template <class T> std::vector<T> convert_base(T x, T b) {
if (x == 0) return {0};
assert(b);
std::vector<T> res;
T k = abs(b);
while (x) {
res.emplace_back(x % k);
if (res.back() < 0) res.back() += k;
x -= res.back();
x /= b;
}
return res;
}
template <class T> T from_base(const std::vector<T> &v, T b) {
assert(b);
T res = 0;
for (int i = v.size() - 1; i >= 0; i--) res = res * b + v[i];
return res;
}
} // namespace kk2
#endif // KK2_MATH_CONVERT_BASE_HPP
#ifndef KK2_MATH_POW_HPP
#define KK2_MATH_POW_HPP 1
namespace kk2 {
template <class S, class T, class U> constexpr S pow(T x, U n) {
assert(n >= 0);
S r = 1, y = x;
while (n) {
if (n & 1) r *= y;
if (n >>= 1) y *= y;
}
return r;
}
} // namespace kk2
#endif // KK2_MATH_POW_HPP
#ifndef KK2_MATH_MULTIPLICATIVE_FUNCTION_EULER_PHI_HPP
#define KK2_MATH_MULTIPLICATIVE_FUNCTION_EULER_PHI_HPP 1
#ifndef KK2_MATH_PRIME_FACTORIZE_HPP
#define KK2_MATH_PRIME_FACTORIZE_HPP 1
#ifndef KK2_MATH_MOD_POW_MOD_HPP
#define KK2_MATH_MOD_POW_MOD_HPP 1
namespace kk2 {
template <class S, class T, class U> constexpr S pow_mod(T x, U n, T m) {
assert(n >= 0);
if (m == 1) return S(0);
S _m = m, r = 1;
S y = x % _m;
if (y < 0) y += _m;
while (n) {
if (n & 1) r = (r * y) % _m;
y = (y * y) % _m;
n >>= 1;
}
return r;
}
} // namespace kk2
#endif // KK2_MATH_MOD_POW_MOD_HPP
#ifndef KK2_MODINT_MONT_ARB_HPP
#define KK2_MODINT_MONT_ARB_HPP 1
namespace kk2 {
template <typename Int, typename UInt, typename Long, typename ULong, int id>
struct ArbitraryLazyMontgomeryModIntBase {
using mint = ArbitraryLazyMontgomeryModIntBase;
inline static UInt mod;
inline static UInt r;
inline static UInt n2;
static constexpr int bit_length = sizeof(UInt) * 8;
static UInt get_r() {
UInt ret = mod;
while (mod * ret != 1) ret *= UInt(2) - mod * ret;
return ret;
}
static void setmod(UInt m) {
assert(m < (UInt(1u) << (bit_length - 2)));
assert((m & 1) == 1);
mod = m, n2 = -ULong(m) % m, r = get_r();
}
UInt _v;
ArbitraryLazyMontgomeryModIntBase() : _v(0) {}
template <class T, is_integral_t<T> * = nullptr>
ArbitraryLazyMontgomeryModIntBase(const T &b) : _v(reduce(ULong(b % mod + mod) * n2)) {}
static UInt reduce(const ULong &b) {
return (b + ULong(UInt(b) * UInt(-r)) * mod) >> bit_length;
}
mint &operator+=(const mint &b) {
if (Int(_v += b._v - 2 * mod) < 0) _v += 2 * mod;
return *this;
}
mint &operator-=(const mint &b) {
if (Int(_v -= b._v) < 0) _v += 2 * mod;
return *this;
}
mint &operator*=(const mint &b) {
_v = reduce(ULong(_v) * b._v);
return *this;
}
mint &operator/=(const mint &b) {
*this *= b.inv();
return *this;
}
friend mint operator+(const mint &a, const mint &b) { return mint(a) += b; }
friend mint operator-(const mint &a, const mint &b) { return mint(a) -= b; }
friend mint operator*(const mint &a, const mint &b) { return mint(a) *= b; }
friend mint operator/(const mint &a, const mint &b) { return mint(a) /= b; }
bool operator==(const mint &b) const {
return (_v >= mod ? _v - mod : _v) == (b._v >= mod ? b._v - mod : b._v);
}
bool operator!=(const mint &b) const {
return (_v >= mod ? _v - mod : _v) != (b._v >= mod ? b._v - mod : b._v);
}
mint operator-() const { return mint(0) - mint(*this); }
mint operator+() const { return mint(*this); }
template <class T> mint pow(T n) const {
mint ret(1), mul(*this);
while (n > 0) {
if (n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
mint inv() const {
Int s = getmod(), t = val(), m0 = 0, m1 = 1;
while (t) {
Int u = s / t;
std::swap(s -= t * u, t);
std::swap(m0 -= m1 * u, m1);
}
if (m0 < 0) m0 += getmod();
return mint(m0);
}
template <class OStream, is_ostream_t<OStream> * = nullptr>
friend OStream &operator<<(OStream &os, const mint &x) {
return os << x.val();
}
template <class IStream, is_istream_t<IStream> * = nullptr>
friend IStream &operator>>(IStream &is, mint &x) {
Long t;
is >> t;
x = mint(t);
return (is);
}
UInt val() const {
UInt ret = reduce(_v);
return ret >= mod ? ret - mod : ret;
}
static UInt getmod() { return mod; }
};
template <int id>
using ArbitraryLazyMontgomeryModInt =
ArbitraryLazyMontgomeryModIntBase<int, unsigned int, long long, unsigned long long, id>;
template <int id>
using ArbitraryLazyMontgomeryModInt64bit =
ArbitraryLazyMontgomeryModIntBase<long long, unsigned long long, __int128_t, __uint128_t, id>;
} // namespace kk2
#endif // KK2_MODINT_MONT_ARB_HPP
#ifndef KK2_RANDOM_GEN_HPP
#define KK2_RANDOM_GEN_HPP 1
#ifndef KK2_RANDOM_SEED_HPP
#define KK2_RANDOM_SEED_HPP 1
namespace kk2 {
namespace random {
using u64 = unsigned long long;
inline u64 non_deterministic_seed() {
u64 seed = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count();
seed ^= reinterpret_cast<u64>(&seed);
seed ^= seed << 5;
seed ^= seed >> 41;
seed ^= seed << 20;
return seed;
}
inline u64 deterministic_seed() {
return 5801799128519729247ull;
}
inline u64 seed() {
#if defined(KK2_RANDOM_DETERMINISTIC)
return deterministic_seed();
#else
return non_deterministic_seed();
#endif
}
} // namespace random
} // namespace kk2
#endif // KK2_RANDOM_SEED_HPP
namespace kk2 {
namespace random {
using i64 = long long;
using u64 = unsigned long long;
inline u64 rng() {
static std::mt19937_64 mt(kk2::random::seed());
return mt();
}
// [l, r)
inline i64 rng(i64 l, i64 r) {
assert(l < r);
return l + rng() % (r - l);
}
// [l, r)
template <class T> std::vector<T> random_vector(int n, T l, T r) {
std::vector<T> res(n);
for (int i = 0; i < n; i++) res[i] = rng(l, r);
return res;
}
// [l, r)
std::vector<i64> distinct_rng(i64 l, i64 r, i64 n) {
assert(l < r and n <= r - l);
std::unordered_set<i64> st;
for (i64 i = n; i; --i) {
i64 m = rng(l, r + 1 - i);
if (st.find(m) != st.end()) m = r - i;
st.insert(m);
}
std::vector<i64> res(st.begin(), st.end());
std::sort(res.begin(), res.end());
return res;
}
template <class Iter> void shuffle(Iter first, Iter last) {
if (first == last) return;
int len = 1;
for (auto it = first + 1; it != last; ++it) {
len++;
int j = rng(0, len);
if (j != len - 1) std::iter_swap(first + j, it);
}
}
template <class T> std::vector<T> perm(int n) {
std::vector<T> res(n);
std::iota(res.begin(), res.end(), T(0));
shuffle(res.begin(), res.end());
return res;
}
template <class T> std::vector<T> choices(int l, int r, int k) {
assert(l < r and k <= r - l);
std::vector<T> res(r - l);
std::iota(res.begin(), res.end(), T(l));
shuffle(res.begin(), res.end());
res.resize(k);
return res;
}
} // namespace random
} // namespace kk2
#endif // KK2_RANDOM_GEN_HPP
#ifndef KK2_MATH_IS_PRIME_HPP
#define KK2_MATH_IS_PRIME_HPP 1
namespace kk2 {
namespace number_theory {
template <class T, class U> bool miller_rabin(const T &n, const std::vector<T> &ws) {
if (n <= 2) return n == 2;
if (~n & 1) return false;
T d = n - 1;
while (~d & 1) d >>= 1;
U e = 1, rev = n - 1;
for (T w : ws) {
if (w % n == 0) continue;
T t = d;
U y = pow_mod<T, T, U>(w, t, n);
while (t != n - 1 and y != e and y != rev) {
y = y * y % n;
t <<= 1;
}
if (y != rev and ~t & 1) return false;
}
return true;
}
bool miller_rabin_u64(unsigned long long n) {
return miller_rabin<unsigned long long, __uint128_t>(
n, {2, 325, 9375, 28178, 450775, 9780504, 1795265022});
}
template <class mint>
bool miller_rabin_mont(unsigned long long n, const std::vector<unsigned long long> &ws) {
if (n <= 2) return n == 2;
if (~n & 1) return false;
if (mint::getmod() != n) mint::setmod(n);
unsigned long long d = n - 1;
while (~d & 1) d >>= 1;
mint e = 1, rev = n - 1;
for (unsigned long long w : ws) {
if (w % n == 0) continue;
unsigned long long t = d;
mint y = mint(w).pow(t);
while (t != n - 1 and y != e and y != rev) {
y *= y;
t <<= 1;
}
if (y != rev and ~t & 1) return false;
}
return true;
}
bool is_prime(unsigned long long n) {
using mint32 = ArbitraryLazyMontgomeryModInt<54305750>;
using mint64 = ArbitraryLazyMontgomeryModInt64bit<54305750>;
if (n <= 2) return n == 2;
if (~n & 1) return false;
if (n < (1ull << 30)) {
return miller_rabin_mont<mint32>(n, {2, 7, 61});
} else if (n < (1ull << 62)) {
return miller_rabin_mont<mint64>(n, {2, 325, 9375, 28178, 450775, 9780504, 1795265022});
} else {
return miller_rabin_u64(n);
}
}
}; // namespace number_theory
using number_theory::is_prime;
}; // namespace kk2
#endif // KK2_MATH_IS_PRIME_HPP
namespace kk2 {
namespace number_theory {
using i64 = long long;
using u64 = unsigned long long;
template <class mint, class T> T pollard_rho(T n) {
if (~n & 1) return 2;
if (is_prime(n)) return n;
if (mint::getmod() != n) mint::setmod(n);
mint R, one = 1;
auto f = [&](mint x) {
return x * x + R;
};
auto _rng = [&]() {
return kk2::random::rng(2, n);
};
while (true) {
mint x, y, ys, q = one;
R = _rng(), y = _rng();
T g = 1;
constexpr int m = 128;
for (int r = 1; g == 1; r <<= 1) {
x = y;
for (int i = 0; i < r; i++) y = f(y);
for (int k = 0; k < r && g == 1; k += m) {
ys = y;
for (int i = 0; i < std::min(m, r - k); i++) {
y = f(y);
q *= x - y;
}
g = std::gcd(q.val(), n);
}
}
if (g == n) do {
ys = f(ys);
g = std::gcd((x - ys).val(), n);
} while (g == 1);
if (g != n) return g;
}
exit(1);
}
std::vector<i64> inner_factorize(i64 n) {
using mint32 = ArbitraryLazyMontgomeryModInt<54355165>;
using mint64 = ArbitraryLazyMontgomeryModInt64bit<54355165>;
assert(n);
if (n < 0) n = -n;
if (n == 1) return {};
u64 p;
if (n <= (1ll << 30)) {
p = pollard_rho<mint32, unsigned int>(n);
} else if (n <= (1ll << 62)) {
p = pollard_rho<mint64, unsigned long long>(n);
} else {
exit(1);
}
if (i64(p) == n) return {i64(p)};
auto l = inner_factorize(p);
auto r = inner_factorize(n / p);
std::copy(r.begin(), r.end(), std::back_inserter(l));
return l;
}
std::vector<std::pair<i64, int>> factorize(i64 n) {
auto tmp = inner_factorize(n);
std::sort(tmp.begin(), tmp.end());
std::vector<std::pair<i64, int>> res;
for (int i = 0; i < (int)tmp.size(); i++) {
if (i == 0 or res.back().first != tmp[i]) {
res.emplace_back(tmp[i], 1);
} else {
res.back().second++;
}
}
return res;
}
std::map<i64, int> factorize_map(i64 n) {
auto tmp = inner_factorize(n);
std::map<i64, int> res;
for (auto x : tmp) res[x]++;
return res;
}
std::vector<i64> divisors(i64 n) {
if (n == 0) return {};
auto f = factorize(n);
std::vector<i64> res = {1};
for (auto [p, k] : f) {
int sz = res.size();
i64 x = 1;
for (int i = 0; i < k; i++) {
x *= p;
for (int j = 0; j < sz; j++) { res.emplace_back(res[j] * x); }
}
}
std::sort(res.begin(), res.end());
return res;
}
} // namespace number_theory
using number_theory::divisors;
using number_theory::factorize;
using number_theory::factorize_map;
} // namespace kk2
#endif // KK2_MATH_PRIME_FACTORIZE_HPP
namespace kk2 {
template <class T, is_integral_t<T> * = nullptr>
T euler_phi(T n) {
assert(n > 0);
for (auto [p, k] : factorize(static_cast<long long>(n))) n -= n / p;
return n;
}
} // namespace kk2
#endif // KK2_MATH_MULTIPLICATIVE_FUNCTION_EULER_PHI_HPP
using namespace std;
void solve() {
/*
レピュニット数とか
10の倍数ではない
2冪, 5冪をどう処理するのか
610016
みたいにして,繰り返す
(10^{ik} - 1) / (10^i - 1)
で,10^i - 1のぶんだけ,nを大きくしておこう
*/
i64 n;
kin >> n;
int v2 = kk2::divide_max_times(n, 2);
int v5 = kk2::divide_max_times(n, 5);
string s;
if (v2) {
i64 m = 1ll << v2;
auto t = kk2::convert_base<i64>(m, 10);
string t2(t.size(), '0');
rep (i, t.size()) t2[i] = '0' + t[i];
string t3 = t2;
reverse(all(t3));
t2.resize(v2, '0');
s = t2 + t3;
reverse(all(s));
} else if (v5) {
i64 m = kk2::pow<i64>(5, v5);
auto t = kk2::convert_base<i64>(m, 10);
string t2(t.size(), '0');
rep (i, t.size()) t2[i] = '0' + t[i];
string t3 = t2;
reverse(all(t3));
t2.resize(v5, '0');
s = t2 + t3;
reverse(all(s));
} else {
s = "1";
}
i64 next = n;
int k = s.size();
for (auto [p, e] : kk2::factorize(n)) {
i64 m = 1;
while (kk2::pow_mod<i128, i64, i64>(10, k, m * p) == 1) m *= p;
next *= m;
}
n = next;
kout << 1 << kendl;
kout << s << " " << kk2::euler_phi(n) << kendl;
}
int main() {
int t = 1;
// kin >> t;
rep (t) solve();
return 0;
}
// Author: kk2
// converted by https://github.com/kk2a/cpp-bundle
// 2025-04-01 09:42:54