結果

問題 No.2795 Perfect Number
ユーザー dekatindekatin
提出日時 2024-06-29 12:41:49
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 25,151 bytes
コンパイル時間 5,733 ms
コンパイル使用メモリ 307,996 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-29 12:41:57
合計ジャッジ時間 7,054 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 10 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "lib/template.hpp"
#include <bits/stdc++.h>
using namespace std;

#define int long long
using ll = long long;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
#define str string
using db = long double;

template <class T> constexpr T infty = 0;
template <> constexpr int32_t infty<int32_t> = 1'000'000'000;
template <> constexpr ll infty<ll> = ll(infty<int32_t>) * infty<int32_t> * 2;
template <> constexpr u32 infty<u32> = infty<int32_t>;
template <> constexpr u64 infty<u64> = infty<ll>;
template <> constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <> constexpr double infty<double> = infty<ll>;
template <> constexpr long double infty<long double> = infty<ll>;

using pi = pair<int, int>;
using pd = pair<db, db>;
#define mp make_pair
#define f first
#define s second

#define tcT template <class T
#define tcTU tcT, class U
tcT > using V = vector<T>;
tcT, size_t SZ > using AR = array<T, SZ>;
using vi = V<int>;
using vb = V<bool>;
using vd = V<db>;
using vs = V<string>;
using vpi = V<pi>;
using vpd = V<pd>;
tcT > using pqg = priority_queue<T, vector<T>, greater<T>>;

#define sz(x) (int)((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()

tcT > T POP(V<T>& a) {
    T res = a.bk;
    a.pop_back();
    return res;
}

#define lb lower_bound
#define ub upper_bound
tcT > int lwb(V<T>& a, const T& b) { return (int)(lb(all(a), b) - bg(a)); }
tcT > int upb(V<T>& a, const T& b) { return (int)(ub(all(a), b) - bg(a)); }

#define each(a, x) for (auto& a : x)
#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep3(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = (ll)(a); i < (ll)(b); i += (c))
#define cut4(a, b, c, d, e, ...) e
#define rep(...) cut4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define per1(n) for (ll _ = ((ll)n) - 1; _ >= 0; --_)
#define per2(i, n) for (ll i = ((ll)n) - 1; i >= 0; --i)
#define per3(i, a, b) for (ll i = ((ll)b) - 1; i >= (ll)(a); --i)
#define per4(i, a, b, c) for (ll i = ((ll)b) - 1; i >= (ll)(a); i -= (c))
#define per(...) cut4(__VA_ARGS__, per4, per3, per2, per1)(__VA_ARGS__)
#define rep_subset(i, s) \
    for (ll i = (s); i >= 0; i = (i == 0 ? -1 : (i - 1) & (s)))

const int dx[8]{1, 0, -1, 0, 1, 1, -1, -1}, dy[8]{0, 1, 0, -1, 1, -1, 1, -1};

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int topbit(int x) { return x == 0 ? 0 : 63 - __builtin_clzll(x); }
constexpr int lowbit(int x) { return x == 0 ? 0 : __builtin_ctzll(x); }
constexpr int isp2(int x) { return x && (x & -x) == x; }
constexpr int mask(int x) { return (1ll << x) - 1; }

int cdiv(int a, int b) { return a / b + ((a ^ b) > 0 && a % b); }

int fdiv(int a, int b) { return a / b - ((a ^ b) < 0 && a % b); }

int root2(int x) {
    int res = sqrtl(x) + 2;
    while (res * res > x) --res;
    return res;
}

tcT > bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }

tcT > bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

tcTU > T fstTrue(T lo, T hi, U f) {
    ++hi;
    assert(lo <= hi);
    while (lo < hi) {
        T mid = lo + (hi - lo) / 2;
        f(mid) ? hi = mid : lo = mid + 1;
    }
    return lo;
}

tcTU > T lstTrue(T lo, T hi, U f) {
    --lo;
    assert(lo <= hi);
    while (lo < hi) {
        T mid = lo + (hi - lo + 1) / 2;
        f(mid) ? lo = mid : hi = mid - 1;
    }
    return lo;
}

tcT > void Unique(vector<T>& v) {
    sort(all(v));
    v.erase(unique(all(v)), end(v));
}

tcT > V<T> prefSum(V<T>& a, int off = 1) {
    int N = sz(a);
    V<T> ret(N + 1);
    rep(i, N) ret[i + 1] = ret[i] + a[i];
    if (off == 0) ret.erase(ret.begin());
    return ret;
}

tcT > V<T> sufSum(const V<T>& a) {
    V<T> ret = a;
    per(i, sz(ret) - 1) ret[i] += ret[i + 1];
    return ret;
}

// sorted[i] = v[idx[i]]
tcT > vi sortedIdx(const V<T>& v) {
    vi ret(sz(v));
    iota(all(ret), 0);
    sort(all(ret), [&](int i, int j) { return v[i] < v[j]; });
    return ret;
}

tcT > vi rearrange(const V<T>& v, const vi& idx) {
    vi ret(sz(v));
    rep(i, sz(v)) ret[i] = v[idx[i]];
    return ret;
}

// ? = -1
tcT > vi str_to_vi(const str& S, T first_char) {
    vi A(sz(S));
    rep(i, sz(S)) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
    return A;
}

tcT > vi Cnt(const V<T>& v, int mx) {
    vi cnt(mx + 1);
    each(x, v) cnt[x]++;
    return cnt;
}

tcT > T Sum(const V<T>& v) {
    T ret = 0;
    each(x, v) ret += x;
    return ret;
}

tcT > T Max(const V<T>& v) { return *max_element(all(v)); }

tcT > T Min(const V<T>& v) { return *min_element(all(v)); }

tcT > int MaxIdx(const V<T>& v) { return max_element(all(v)) - bg(v); }

tcT > int MinIdx(const V<T>& v) { return min_element(all(v)) - bg(v); }

tcT > V<T> Transpose(const V<T>& v) {
    using U = typename T::value_type;
    if (v.empty()) return {};
    int H = v.size(), W = v[0].size();
    vector res(W, T(H, U{}));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            res[j][i] = v[i][j];
        }
    }
    return res;
}

tcT > V<T> Rotate(const V<T>& v, int clockwise = true) {
    using U = typename T::value_type;
    int H = v.size(), W = v[0].size();
    vector res(W, T(H, U{}));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (clockwise) {
                res[j][H - 1 - i] = v[i][j];
            } else {
                res[W - 1 - j][i] = v[i][j];
            }
        }
    }
    return res;
}

inline namespace IO {
#define SFINAE(x, ...)                                            \
    template <class, class = void> struct x : std::false_type {}; \
    template <class T> struct x<T, std::void_t<__VA_ARGS__>> : std::true_type {}

SFINAE(DefaultI, decltype(std::cin >> std::declval<T&>()));
SFINAE(DefaultO, decltype(std::cout << std::declval<T&>()));
SFINAE(IsTuple, typename std::tuple_size<T>::type);
SFINAE(Iterable, decltype(std::begin(std::declval<T>())));

template <auto& is> struct Reader {
    template <class T> void Impl(T& t) {
        if constexpr (DefaultI<T>::value)
            is >> t;
        else if constexpr (Iterable<T>::value) {
            for (auto& x : t) Impl(x);
        } else if constexpr (IsTuple<T>::value) {
            std::apply([this](auto&... args) { (Impl(args), ...); }, t);
        } else
            static_assert(IsTuple<T>::value, "No matching type for read");
    }
    template <class... Ts> void read(Ts&... ts) { ((Impl(ts)), ...); }
};

template <class... Ts> void re(Ts&... ts) { Reader<cin>{}.read(ts...); }
#define def(t, args...) \
    t args;             \
    re(args);

#define defi(args...) def(int, args)
#define defs(args...) def(str, args)
#define defd(args...) def(db, args)
#define defv(t, name, size) \
    V<t> name(size);        \
    re(name);

#define defvi1(name, size) \
    vi name(size);         \
    re(name);

#define defvi2(name, size, offset) \
    vi name(size + offset);        \
    rep(i, offset, size + offset) re(name[i]);

#define cut3(a, b, c, d, ...) d
#define defvi(...) cut3(__VA_ARGS__, defvi2, defvi1)(__VA_ARGS__)

#define re2(s, t)                     \
    for (int i = 0; i < sz(s); i++) { \
        re(s[i], t[i]);               \
    }

#define re3(s, t, u)                  \
    for (int i = 0; i < sz(s); i++) { \
        re(s[i], t[i], u[i]);         \
    }

#define re4(s, t, u, v)               \
    for (int i = 0; i < sz(s); i++) { \
        re(s[i], t[i], u[i], v[i]);   \
    }

template <auto& os, bool debug, bool print_nd> struct Writer {
    string comma() const { return debug ? "," : ""; }
    template <class T> constexpr char Space(const T&) const {
        return print_nd && (Iterable<T>::value or IsTuple<T>::value) ? '\n'
                                                                     : ' ';
    }
    template <class T> void Impl(T const& t) const {
        if constexpr (DefaultO<T>::value)
            os << t;
        else if constexpr (Iterable<T>::value) {
            if (debug) os << '{';
            int i = 0;
            for (auto&& x : t)
                ((i++) ? (os << comma() << Space(x), Impl(x)) : Impl(x));
            if (debug) os << '}';
        } else if constexpr (IsTuple<T>::value) {
            if (debug) os << '(';
            std::apply(
                [this](auto const&... args) {
                    int i = 0;
                    (((i++) ? (os << comma() << " ", Impl(args)) : Impl(args)),
                     ...);
                },
                t);
            if (debug) os << ')';
        } else
            static_assert(IsTuple<T>::value, "No matching type for print");
    }
    template <class T> void ImplWrapper(T const& t) const { Impl(t); }
    template <class... Ts> void print(Ts const&... ts) const {
        ((Impl(ts)), ...);
    }
    template <class F, class... Ts>
    void print_with_sep(const std::string& sep,
                        F const& f,
                        Ts const&... ts) const {
        ImplWrapper(f), ((os << sep, ImplWrapper(ts)), ...), os << '\n';
    }
    void print_with_sep(const std::string&) const { os << '\n'; }
};

template <class... Ts> void pr(Ts const&... ts) {
    Writer<cout, false, true>{}.print(ts...);
}
template <class... Ts> void ps(Ts const&... ts) {
    Writer<cout, false, true>{}.print_with_sep(" ", ts...);
}
}  // namespace IO

inline namespace Debug {
template <typename... Args> void err(Args... args) {
    Writer<cerr, true, false>{}.print_with_sep(" | ", args...);
}

void err_prefix(string func, int line, string args) {
    cerr << func << ":" << line << " - " << "[" << args << "] = ";
}

#ifdef LOCAL
#define dbg(args...) err_prefix(__FUNCTION__, __LINE__, #args), err(args)
#else
#define dbg(...)
#endif

void setIO() {
    cin.tie(0)->sync_with_stdio(0);
    cout << fixed << setprecision(12);
}
}  // namespace Debug

void YES(bool t = 1) { ps(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { ps(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { ps(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }

namespace std {

template <class Fun> class y_combinator_result {
    Fun fun_;

  public:
    template <class T>
    explicit y_combinator_result(T&& fun) : fun_(std::forward<T>(fun)) {}

    template <class... Args> decltype(auto) operator()(Args&&... args) {
        return fun_(std::ref(*this), std::forward<Args>(args)...);
    }
};

template <class Fun> decltype(auto) fun(Fun&& fun) {
    return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}  // usage : fun([&](auto dfs, int u, int p) -> void ...

}  // namespace std
#line 4 "lib/fast-factorize.hpp"
using namespace std;

#line 2 "lib/rng.hpp"

#line 2 "lib/internal-seed.hpp"
using namespace std;

namespace internal {
unsigned long long non_deterministic_seed() {
    unsigned long long m =
        chrono::duration_cast<chrono::nanoseconds>(
            chrono::high_resolution_clock::now().time_since_epoch())
            .count();
    m ^= 9845834732710364265uLL;
    m ^= m << 24, m ^= m >> 31, m ^= m << 35;
    return m;
}
unsigned long long deterministic_seed() { return 88172645463325252UL; }

// 64 bit の seed 値を生成 (手元では seed 固定)
// 連続で呼び出すと同じ値が何度も返ってくるので注意
// #define RANDOMIZED_SEED するとシードがランダムになる
unsigned long long seed() {
#ifdef LOCAL
    return deterministic_seed();
#else
    return non_deterministic_seed();
#endif
}

}  // namespace internal
#line 4 "lib/rng.hpp"

namespace my_rand {
using i64 = long long;
using u64 = unsigned long long;

// [0, 2^64 - 1)
u64 rng() {
    static u64 _x = internal::seed();
    return _x ^= _x << 7, _x ^= _x >> 9;
}

// [l, r]
i64 rng(i64 l, i64 r) {
    assert(l <= r);
    return l + rng() % u64(r - l + 1);
}

// [l, r)
i64 randint(i64 l, i64 r) {
    assert(l < r);
    return l + rng() % u64(r - l);
}

// choose n numbers from [l, r) without overlapping
vector<i64> randset(i64 l, i64 r, i64 n) {
    assert(l <= r && n <= r - l);
    unordered_set<i64> s;
    for (i64 i = n; i; --i) {
        i64 m = randint(l, r + 1 - i);
        if (s.find(m) != s.end()) m = r - i;
        s.insert(m);
    }
    vector<i64> ret;
    for (auto& x : s) ret.push_back(x);
    sort(begin(ret), end(ret));
    return ret;
}

// [0.0, 1.0)
double rnd() { return rng() * 5.42101086242752217004e-20; }
// [l, r)
double rnd(double l, double r) {
    assert(l < r);
    return l + rnd() * (r - l);
}

template <typename T> void randshf(vector<T>& v) {
    int n = v.size();
    for (int i = 1; i < n; i++) swap(v[i], v[randint(0, i + 1)]);
}

}  // namespace my_rand

using my_rand::randint;
using my_rand::randset;
using my_rand::randshf;
using my_rand::rnd;
using my_rand::rng;
#line 2 "lib/miller-rabin.hpp"
using namespace std;

#line 2 "lib/arbitrary-montgomery-modint.hpp"
using namespace std;

template <typename Int, typename UInt, typename Long, typename ULong, int32_t id>
struct ArbitraryLazyMontgomeryModIntBase {
    using mint = ArbitraryLazyMontgomeryModIntBase;

    inline static UInt mod;
    inline static UInt r;
    inline static UInt n2;
    static constexpr int32_t 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 set_mod(UInt m) {
        assert(m < (UInt(1u) << (bit_length - 2)));
        assert((m & 1) == 1);
        mod = m, n2 = -ULong(m) % m, r = get_r();
    }
    UInt a;

    ArbitraryLazyMontgomeryModIntBase() : a(0) {}
    ArbitraryLazyMontgomeryModIntBase(const Long& b)
        : a(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(a += b.a - 2 * mod) < 0) a += 2 * mod;
        return *this;
    }
    mint& operator-=(const mint& b) {
        if (Int(a -= b.a) < 0) a += 2 * mod;
        return *this;
    }
    mint& operator*=(const mint& b) {
        a = reduce(ULong(a) * b.a);
        return *this;
    }
    mint& operator/=(const mint& b) {
        *this *= b.inverse();
        return *this;
    }

    mint operator+(const mint& b) const { return mint(*this) += b; }
    mint operator-(const mint& b) const { return mint(*this) -= b; }
    mint operator*(const mint& b) const { return mint(*this) *= b; }
    mint operator/(const mint& b) const { return mint(*this) /= b; }

    bool operator==(const mint& b) const {
        return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);
    }
    bool operator!=(const mint& b) const {
        return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);
    }
    mint operator-() const { return mint(0) - mint(*this); }
    mint operator+() const { return mint(*this); }

    mint pow(ULong n) const {
        mint ret(1), mul(*this);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul, n >>= 1;
        }
        return ret;
    }

    friend ostream& operator<<(ostream& os, const mint& b) {
        return os << b.get();
    }

    friend istream& operator>>(istream& is, mint& b) {
        Long t;
        is >> t;
        b = ArbitraryLazyMontgomeryModIntBase(t);
        return (is);
    }

    mint inverse() const {
        Int x = get(), y = get_mod(), u = 1, v = 0;
        while (y > 0) {
            Int t = x / y;
            swap(x -= t * y, y);
            swap(u -= t * v, v);
        }
        return mint{u};
    }

    UInt get() const {
        UInt ret = reduce(a);
        return ret >= mod ? ret - mod : ret;
    }

    static UInt get_mod() { return mod; }
};

// id に適当な乱数を割り当てて使う
template <int32_t id>
using ArbitraryLazyMontgomeryModInt =
    ArbitraryLazyMontgomeryModIntBase<int32_t,
                                      uint32_t,
                                      long long,
                                      unsigned long long,
                                      id>;
template <int32_t id>
using ArbitraryLazyMontgomeryModInt64bit =
    ArbitraryLazyMontgomeryModIntBase<long long,
                                      unsigned long long,
                                      __int128_t,
                                      __uint128_t,
                                      id>;
#line 1 "lib/internal-type-traits.hpp"
#include <type_traits>
using namespace std;

namespace internal {
template <typename T>
using is_broadly_integral =
    typename conditional_t<is_integral_v<T> || is_same_v<T, __int128_t> ||
                               is_same_v<T, __uint128_t>,
                           true_type,
                           false_type>::type;

template <typename T>
using is_broadly_signed =
    typename conditional_t<is_signed_v<T> || is_same_v<T, __int128_t>,
                           true_type,
                           false_type>::type;

template <typename T>
using is_broadly_unsigned =
    typename conditional_t<is_unsigned_v<T> || is_same_v<T, __uint128_t>,
                           true_type,
                           false_type>::type;

#define ENABLE_VALUE(x) \
    template <typename T> constexpr bool x##_v = x<T>::value;

ENABLE_VALUE(is_broadly_integral);
ENABLE_VALUE(is_broadly_signed);
ENABLE_VALUE(is_broadly_unsigned);
#undef ENABLE_VALUE

#define ENABLE_HAS_TYPE(var)                                         \
    template <class, class = void> struct has_##var : false_type {}; \
    template <class T>                                               \
    struct has_##var<T, void_t<typename T::var>> : true_type {};     \
    template <class T> constexpr auto has_##var##_v = has_##var<T>::value;

#define ENABLE_HAS_VAR(var)                                          \
    template <class, class = void> struct has_##var : false_type {}; \
    template <class T>                                               \
    struct has_##var<T, void_t<decltype(T::var)>> : true_type {};    \
    template <class T> constexpr auto has_##var##_v = has_##var<T>::value;

}  // namespace internal
#line 2 "lib/internal-math.hpp"

namespace internal {

#line 6 "lib/internal-math.hpp"
using namespace std;

// a mod p
template <typename T> T safe_mod(T a, T p) {
    a %= p;
    if constexpr (is_broadly_signed_v<T>) {
        if (a < 0) a += p;
    }
    return a;
}

// 返り値:pair(g, x)
// s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
template <typename T> pair<T, T> inv_gcd(T a, T p) {
    static_assert(is_broadly_signed_v<T>);
    a = safe_mod(a, p);
    if (a == 0) return {p, 0};
    T b = p, x = 1, y = 0;
    while (a != 0) {
        T q = b / a;
        swap(a, b %= a);
        swap(x, y -= q * x);
    }
    if (y < 0) y += p / b;
    return {b, y};
}

// 返り値 : a^{-1} mod p
// gcd(a, p) != 1 が必要
template <typename T> T inv(T a, T p) {
    static_assert(is_broadly_signed_v<T>);
    a = safe_mod(a, p);
    T b = p, x = 1, y = 0;
    while (a != 0) {
        T q = b / a;
        swap(a, b %= a);
        swap(x, y -= q * x);
    }
    assert(b == 1);
    return y < 0 ? y + p : y;
}

// T : 底の型
// U : T*T がオーバーフローしない かつ 指数の型
template <typename T, typename U> T modpow(T a, U n, T p) {
    a = safe_mod(a, p);
    T ret = 1 % p;
    while (n != 0) {
        if (n % 2 == 1) ret = U(ret) * a % p;
        a = U(a) * a % p;
        n /= 2;
    }
    return ret;
}

// 返り値 : pair(rem, mod)
// 解なしのときは {0, 0} を返す
template <typename T> pair<T, T> crt(const vector<T>& r, const vector<T>& m) {
    static_assert(is_broadly_signed_v<T>);
    assert(r.size() == m.size());
    int n = (int)(r.size());
    T r0 = 0, m0 = 1;
    for (int i = 0; i < n; i++) {
        assert(1 <= m[i]);
        T r1 = safe_mod(r[i], m[i]), m1 = m[i];
        if (m0 < m1) swap(r0, r1), swap(m0, m1);
        if (m0 % m1 == 0) {
            if (r0 % m1 != r1) return {0, 0};
            continue;
        }
        auto [g, im] = inv_gcd(m0, m1);
        T u1 = m1 / g;
        if ((r1 - r0) % g) return {0, 0};
        T x = (r1 - r0) / g % u1 * im % u1;
        r0 += x * m0;
        m0 *= u1;
        if (r0 < 0) r0 += m0;
    }
    return {r0, m0};
}

}  // namespace internal
#line 6 "lib/miller-rabin.hpp"

namespace fast_factorize {

template <typename T, typename U> bool miller_rabin(const T& n, vector<T> ws) {
    if (n <= 2) return n == 2;
    if (n % 2 == 0) return false;

    T d = n - 1;
    while (d % 2 == 0) d /= 2;
    U e = 1, rev = n - 1;
    for (T w : ws) {
        if (w % n == 0) continue;
        T t = d;
        U y = internal::modpow<T, U>(w, t, n);
        while (t != n - 1 && y != e && y != rev) y = y * y % n, t *= 2;
        if (y != rev && t % 2 == 0) 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 <typename mint>
bool miller_rabin(unsigned long long n, vector<unsigned long long> ws) {
    if (n <= 2) return n == 2;
    if (n % 2 == 0) return false;

    if (mint::get_mod() != n) mint::set_mod(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 && y != e && y != rev) y *= y, t *= 2;
        if (y != rev && t % 2 == 0) return false;
    }
    return true;
}

bool is_prime(unsigned long long n) {
    using mint32 = ArbitraryLazyMontgomeryModInt<96229631>;
    using mint64 = ArbitraryLazyMontgomeryModInt64bit<622196072>;

    if (n <= 2) return n == 2;
    if (n % 2 == 0) return false;
    if (n < (1uLL << 30)) {
        return miller_rabin<mint32>(n, {2, 7, 61});
    } else if (n < (1uLL << 62)) {
        return miller_rabin<mint64>(
            n, {2, 325, 9375, 28178, 450775, 9780504, 1795265022});
    } else {
        return miller_rabin_u64(n);
    }
}

}  // namespace fast_factorize

using fast_factorize::is_prime;
#line 8 "lib/fast-factorize.hpp"

namespace fast_factorize {
using u64 = uint64_t;

template <typename mint, typename T> T pollard_rho(T n) {
    if (~n & 1) return 2;
    if (is_prime(n)) return n;
    if (mint::get_mod() != n) mint::set_mod(n);
    mint R, one = 1;
    auto f = [&](mint x) { return x * x + R; };
    auto rnd_ = [&]() { return rng() % (n - 2) + 2; };
    while (1) {
        mint x, y, ys, q = one;
        R = rnd_(), y = rnd_();
        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; g == 1 && k < r; k += m) {
                ys = y;
                for (int i = 0; i < m && i < r - k; ++i) q *= x - (y = f(y));
                g = gcd(q.get(), n);
            }
        }
        if (g == n) do
                g = gcd((x - (ys = f(ys))).get(), n);
            while (g == 1);
        if (g != n) return g;
    }
    exit(1);
}

using i64 = long long;

vector<i64> inner_factorize(u64 n) {
    using mint32 = ArbitraryLazyMontgomeryModInt<452288976>;
    using mint64 = ArbitraryLazyMontgomeryModInt64bit<401243123>;

    if (n <= 1) return {};
    u64 p;
    if (n <= (1LL << 30)) {
        p = pollard_rho<mint32, uint32_t>(n);
    } else if (n <= (1LL << 62)) {
        p = pollard_rho<mint64, uint64_t>(n);
    } else {
        exit(1);
    }
    if (p == n) return {i64(p)};
    auto l = inner_factorize(p);
    auto r = inner_factorize(n / p);
    copy(begin(r), end(r), back_inserter(l));
    return l;
}

vector<i64> factorize(u64 n) {
    auto ret = inner_factorize(n);
    sort(begin(ret), end(ret));
    return ret;
}

map<i64, i64> factor_count(u64 n) {
    map<i64, i64> mp;
    for (auto& x : factorize(n)) mp[x]++;
    return mp;
}

vector<i64> divisors(u64 n) {
    if (n == 0) return {};
    vector<pair<i64, i64>> v;
    for (auto& p : factorize(n)) {
        if (v.empty() || v.back().first != p) {
            v.emplace_back(p, 1);
        } else {
            v.back().second++;
        }
    }
    vector<i64> ret;
    auto f = [&](auto rc, int i, i64 x) -> void {
        if (i == (int)v.size()) {
            ret.push_back(x);
            return;
        }
        rc(rc, i + 1, x);
        for (int j = 0; j < v[i].second; j++) rc(rc, i + 1, x *= v[i].first);
    };
    f(f, 0, 1);
    sort(begin(ret), end(ret));
    return ret;
}

}  // namespace fast_factorize

using fast_factorize::divisors;
using fast_factorize::factor_count;
using fast_factorize::factorize;
#line 3 "main.cpp"

void solve(int tc) {
    defi(n);
    Yes(2 * n == Sum(divisors(n)));
}

signed main() {
    setIO();
    int TC = 1;
    // re(TC);
    rep(i, 1, TC + 1) solve(i);
}
0