結果
問題 | No.1276 3枚のカード |
ユーザー | Pachicobue |
提出日時 | 2020-10-31 00:18:11 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,368 ms / 2,000 ms |
コード長 | 14,898 bytes |
コンパイル時間 | 2,251 ms |
コンパイル使用メモリ | 215,768 KB |
実行使用メモリ | 14,720 KB |
最終ジャッジ日時 | 2024-07-22 04:00:19 |
合計ジャッジ時間 | 42,665 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 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 | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1,155 ms
13,440 KB |
testcase_11 | AC | 556 ms
9,344 KB |
testcase_12 | AC | 697 ms
10,240 KB |
testcase_13 | AC | 719 ms
10,624 KB |
testcase_14 | AC | 68 ms
5,376 KB |
testcase_15 | AC | 594 ms
9,600 KB |
testcase_16 | AC | 1,216 ms
14,080 KB |
testcase_17 | AC | 677 ms
10,240 KB |
testcase_18 | AC | 514 ms
9,216 KB |
testcase_19 | AC | 823 ms
11,392 KB |
testcase_20 | AC | 496 ms
9,088 KB |
testcase_21 | AC | 517 ms
9,216 KB |
testcase_22 | AC | 1,307 ms
14,080 KB |
testcase_23 | AC | 59 ms
5,376 KB |
testcase_24 | AC | 789 ms
11,008 KB |
testcase_25 | AC | 279 ms
7,168 KB |
testcase_26 | AC | 958 ms
12,288 KB |
testcase_27 | AC | 1,114 ms
13,184 KB |
testcase_28 | AC | 1,068 ms
13,056 KB |
testcase_29 | AC | 631 ms
9,856 KB |
testcase_30 | AC | 124 ms
5,504 KB |
testcase_31 | AC | 57 ms
5,376 KB |
testcase_32 | AC | 300 ms
7,168 KB |
testcase_33 | AC | 19 ms
5,376 KB |
testcase_34 | AC | 210 ms
6,400 KB |
testcase_35 | AC | 199 ms
6,940 KB |
testcase_36 | AC | 13 ms
6,944 KB |
testcase_37 | AC | 185 ms
6,944 KB |
testcase_38 | AC | 122 ms
6,940 KB |
testcase_39 | AC | 311 ms
7,296 KB |
testcase_40 | AC | 1,218 ms
13,696 KB |
testcase_41 | AC | 997 ms
12,544 KB |
testcase_42 | AC | 1,063 ms
12,928 KB |
testcase_43 | AC | 935 ms
12,288 KB |
testcase_44 | AC | 1,318 ms
14,464 KB |
testcase_45 | AC | 1,201 ms
13,824 KB |
testcase_46 | AC | 1,222 ms
13,824 KB |
testcase_47 | AC | 1,008 ms
12,416 KB |
testcase_48 | AC | 963 ms
12,160 KB |
testcase_49 | AC | 1,103 ms
13,184 KB |
testcase_50 | AC | 1,214 ms
13,952 KB |
testcase_51 | AC | 1,045 ms
12,800 KB |
testcase_52 | AC | 898 ms
11,776 KB |
testcase_53 | AC | 1,065 ms
12,800 KB |
testcase_54 | AC | 1,208 ms
13,824 KB |
testcase_55 | AC | 939 ms
12,160 KB |
testcase_56 | AC | 902 ms
11,904 KB |
testcase_57 | AC | 1,137 ms
13,312 KB |
testcase_58 | AC | 1,204 ms
13,696 KB |
testcase_59 | AC | 1,078 ms
12,672 KB |
testcase_60 | AC | 1,368 ms
14,720 KB |
ソースコード
#include <bits/stdc++.h> using ll = long long; using uint = unsigned int; using ull = unsigned long long; using ld = long double; template<typename T> using max_heap = std::priority_queue<T>; template<typename T> using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template<typename T> constexpr std::pair<T, T> extgcd(const T a, const T b) { if (b == 0) { return std::pair<T, T>{1, 0}; } const auto g = std::gcd(a, b), da = std::abs(b) / g; const auto p = extgcd(b, a % b); const auto x = (da + p.second % da) % da, y = (g - a * x) / b; return {x, y}; } template<typename T> constexpr T inverse(const T a, const T mod) { return extgcd(a, mod).first; } template<uint mod_value, bool dynamic = false> class modint_base { public: template<typename UInt = uint> static std::enable_if_t<dynamic, const UInt> mod() { return mod_ref(); } template<typename UInt = uint> static constexpr std::enable_if_t<not dynamic, const UInt> mod() { return mod_value; } template<typename UInt = uint> static void set_mod(const std::enable_if_t<dynamic, const UInt> mod) { mod_ref() = mod, inv_ref() = {1, 1}; } modint_base() : v{0} {} modint_base(const ll val) : v{norm(static_cast<uint>(val % static_cast<ll>(mod()) + static_cast<ll>(mod())))} {} modint_base(const modint_base& n) : v{n()} {} explicit operator bool() const { return v != 0; } explicit operator int() const { return v; } explicit operator uint() const { return v; } explicit operator ll() const { return v; } explicit operator ull() const { return v; } bool operator!() const { return not static_cast<bool>(*this); } modint_base& operator=(const modint_base& m) { return v = m(), (*this); } modint_base& operator=(const ll val) { return v = norm(uint(val % static_cast<ll>(mod()) + static_cast<ll>(mod()))), (*this); } friend modint_base operator+(const modint_base& m) { return m; } friend modint_base operator-(const modint_base& m) { return make(norm(mod() - m.v)); } friend modint_base operator+(const modint_base& m1, const modint_base& m2) { return make(norm(m1.v + m2.v)); } friend modint_base operator-(const modint_base& m1, const modint_base& m2) { return make(norm(m1.v + mod() - m2.v)); } friend modint_base operator*(const modint_base& m1, const modint_base& m2) { return make(static_cast<uint>(static_cast<ll>(m1.v) * static_cast<ll>(m2.v) % static_cast<ll>(mod()))); } friend modint_base operator/(const modint_base& m1, const modint_base& m2) { return m1 * inv(m2.v); } friend modint_base operator+(const modint_base& m, const ll val) { return modint_base{static_cast<ll>(m.v) + val}; } friend modint_base operator-(const modint_base& m, const ll val) { return modint_base{static_cast<ll>(m.v) - val}; } friend modint_base operator*(const modint_base& m, const ll val) { return modint_base{static_cast<ll>(m.v) * (val % static_cast<ll>(mod()))}; } friend modint_base operator/(const modint_base& m, const ll val) { return modint_base{static_cast<ll>(m.v) * inv(val)}; } friend modint_base operator+(const ll val, const modint_base& m) { return modint_base{static_cast<ll>(m.v) + val}; } friend modint_base operator-(const ll val, const modint_base& m) { return modint_base{-static_cast<ll>(m.v) + val}; } friend modint_base operator*(const ll val, const modint_base& m) { return modint_base{static_cast<ll>(m.v) * (val % static_cast<ll>(mod()))}; } friend modint_base operator/(const ll val, const modint_base& m) { return modint_base{val * inv(static_cast<ll>(m.v))}; } friend modint_base& operator+=(modint_base& m1, const modint_base& m2) { return m1 = m1 + m2; } friend modint_base& operator-=(modint_base& m1, const modint_base& m2) { return m1 = m1 - m2; } friend modint_base& operator*=(modint_base& m1, const modint_base& m2) { return m1 = m1 * m2; } friend modint_base& operator/=(modint_base& m1, const modint_base& m2) { return m1 = m1 / m2; } friend modint_base& operator+=(modint_base& m, const ll val) { return m = m + val; } friend modint_base& operator-=(modint_base& m, const ll val) { return m = m - val; } friend modint_base& operator*=(modint_base& m, const ll val) { return m = m * val; } friend modint_base& operator/=(modint_base& m, const ll val) { return m = m / val; } friend modint_base operator^(const modint_base& m, const ll n) { return power(m.v, n); } friend modint_base& operator^=(modint_base& m, const ll n) { return m = m ^ n; } friend bool operator==(const modint_base& m1, const modint_base& m2) { return m1.v == m2.v; } friend bool operator!=(const modint_base& m1, const modint_base& m2) { return not(m1 == m2); } friend bool operator==(const modint_base& m, const ll val) { return m.v == norm(static_cast<uint>(static_cast<ll>(mod()) + val % static_cast<ll>(mod()))); } friend bool operator!=(const modint_base& m, const ll val) { return not(m == val); } friend bool operator==(const ll val, const modint_base& m) { return m.v == norm(static_cast<uint>(static_cast<ll>(mod()) + val % static_cast<ll>(mod()))); } friend bool operator!=(const ll val, const modint_base& m) { return not(m == val); } friend std::istream& operator>>(std::istream& is, modint_base& m) { ll v; return is >> v, m = v, is; } friend std::ostream& operator<<(std::ostream& os, const modint_base& m) { return os << m(); } uint operator()() const { return v; } static modint_base fact(const int n) { auto& fact_ = fact_ref(); if (n < (int)fact_.size()) { return fact_[n]; } for (int i = (int)fact_.size(); i <= n; i++) { fact_.push_back(fact_.back() * i); } return fact_.back(); } static modint_base inv_fact(const int n) { auto& inv_fact_ = inv_fact_ref(); if (n < (int)inv_fact_.size()) { return inv_fact_[n]; } for (int i = inv_fact_.size(); i <= n; i++) { inv_fact_.push_back(inv_fact_.back() * modint_base::small_inv(i)); } return inv_fact_.back(); } static modint_base perm(const int n, const int k) { return k > n ? modint_base{0} : fact(n) * inv_fact(n - k); } static modint_base comb(const int n, const int k) { return k > n ? modint_base{0} : fact(n) * inv_fact(n - k) * inv_fact(k); } std::pair<ll, ll> quad() const { const auto ans = quad_r(v, mod()); ll x = std::get<0>(ans), y = std::get<1>(ans); if (y < 0) { x = -x, y = -y; } return {x, y}; } private: static std::tuple<ll, ll, ll> quad_r(const ll r, const ll p) // r = x/y (mod p), (x,y,z) s.t. x=yr+pz { if (std::abs(r) <= 1000) { return {r, 1, 0}; } ll nr = p % r, q = p / r; if (nr * 2LL >= r) { nr -= r, q++; } if (nr * 2LL <= -r) { nr += r, q--; } const auto sub = quad_r(nr, r); const ll x = std::get<0>(sub), z = std::get<1>(sub), y = std::get<2>(sub); return {x, y - q * z, z}; } template<typename UInt = uint> static std::enable_if_t<dynamic, UInt&> mod_ref() { static UInt mod = 0; return mod; } static uint norm(const uint x) { return x < mod() ? x : x - mod(); } static modint_base make(const uint x) { modint_base m; return m.v = x, m; } static modint_base power(modint_base x, ull n) { modint_base ans = 1; for (; n; n >>= 1, x *= x) { if (n & 1) { ans *= x; } } return ans; } static modint_base small_inv(const int n) { auto& inv_ = inv_ref(); if (n < (int)inv_.size()) { return inv_[n]; } for (int i = inv_.size(); i <= n; i++) { inv_.push_back(-inv_[modint_base::mod() % i] * (modint_base::mod() / i)); } return inv_.back(); } static modint_base inv(const ll v) { return v <= 2000000 ? small_inv(static_cast<int>(v)) : modint_base{inverse(v, static_cast<ll>(mod()))}; } static std::vector<modint_base>& inv_ref() { static std::vector<modint_base> inv_{1, 1}; return inv_; } static std::vector<modint_base>& fact_ref() { static std::vector<modint_base> fact_{1, 1}; return fact_; } static std::vector<modint_base>& inv_fact_ref() { static std::vector<modint_base> inv_fact_{1, 1}; return inv_fact_; } uint v; }; template<uint mod> using modint = modint_base<mod, false>; template<uint id> using dynamic_modint = modint_base<id, true>; constexpr int popcount(const ull v) { return v ? __builtin_popcountll(v) : 0; } constexpr int log2p1(const ull v) { return v ? 64 - __builtin_clzll(v) : 0; } constexpr int lsbp1(const ull v) { return __builtin_ffsll(v); } constexpr int clog(const ull v) { return v ? log2p1(v - 1) : 0; } constexpr ull ceil2(const ull v) { return 1ULL << clog(v); } constexpr ull floor2(const ull v) { return v ? (1ULL << (log2p1(v) - 1)) : 0ULL; } constexpr bool btest(const ull mask, const int ind) { return (mask >> ind) & 1ULL; } template<typename T> void bset(T& mask, const int ind) { mask |= ((T)1 << ind); } template<typename T> void breset(T& mask, const int ind) { mask &= ~((T)1 << ind); } template<typename T> void bflip(T& mask, const int ind) { mask ^= ((T)1 << ind); } template<typename T> void bset(T& mask, const int ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); } template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); } template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); } template<typename T> constexpr T inf_v = std::numeric_limits<T>::max() / 4; template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; template<typename T> constexpr T TEN(const int n) { return n == 0 ? T{1} : TEN<T>(n - 1) * T{10}; } template<typename F> struct fix : F { fix(F&& f) : F{std::forward<F>(f)} {} template<typename... Args> auto operator()(Args&&... args) const { return F::operator()(*this, std::forward<Args>(args)...); } }; template<typename T, int n, int i = 0> auto nd_array(int const (&szs)[n], const T x = T{}) { if constexpr (i == n) { return x; } else { return std::vector(szs[i], nd_array<T, n, i + 1>(szs, x)); } } class printer { public: printer(std::ostream& os_ = std::cout) : m_os{os_} { m_os << std::fixed << std::setprecision(15); } template<typename... Args> int ln(const Args&... args) { return dump(args...), m_os << '\n', 0; } template<typename... Args> int el(const Args&... args) { return dump(args...), m_os << std::endl, 0; } template<typename... Args> int fmt(const std::string& s, const Args&... args) { return rec(s, 0, args...); } private: template<typename T> int dump(const T& v) { return m_os << v, 0; } template<typename T> int dump(const std::vector<T>& vs) { for (int i = 0; i < (int)vs.size(); i++) { m_os << (i ? " " : ""), dump(vs[i]); } return 0; } template<typename T> int dump(const std::vector<std::vector<T>>& vss) { for (int i = 0; i < (int)vss.size(); i++) { m_os << (0 <= i or i + 1 < (int)vss.size() ? "\n" : ""), dump(vss[i]); } return 0; } template<typename T, typename... Args> int dump(const T& v, const Args&... args) { return dump(v), m_os << ' ', dump(args...), 0; } int rec(const std::string& s, int index) { return m_os << s.substr(index, s.size()), 0; } template<typename T, typename... Args> int rec(const std::string& s, int index, const T& v, const Args&... args) { return index == s.size() ? 0 : s[index] == '%' ? (tdump(v), rec(s, index + 1, args...)) : (m_os << s[index], rec(s, index + 1, v, args...)); } std::ostream& m_os; }; printer out; class scanner { public: scanner(std::istream& is_ = std::cin) : m_is{is_} { m_is.tie(nullptr), std::ios::sync_with_stdio(false); } template<typename T> T val() { T v; return m_is >> v, v; } template<typename T> T val(const T offset) { return val<T>() - offset; } template<typename T> std::vector<T> vec(const int n) { return make_v<T>(n, [this]() { return val<T>(); }); } template<typename T> std::vector<T> vec(const int n, const T offset) { return make_v<T>(n, [this, offset]() { return val<T>(offset); }); } template<typename T> std::vector<std::vector<T>> vvec(const int n0, const int n1) { return make_v<T>(n0, [this, n1]() { return vec<T>(n1); }); } template<typename T> std::vector<std::vector<T>> vvec(const int n0, const int n1, const T offset) { return make_v<T>(n0, [this, n1, offset]() { return vec<T>(n1, offset); }); } template<typename... Args> auto tup() { return std::tuple<std::decay_t<Args>...>{val<Args>()...}; } template<typename... Args> auto tup(const Args&... offsets) { return std::tuple<std::decay_t<Args>...>{val<Args>(offsets)...}; } private: template<typename T, typename F> std::vector<T> make_v(const int n, F f) { std::vector<T> ans; for (int i = 0; i < n; i++) { ans.push_back(f()); } return ans; } std::istream& m_is; }; scanner in; # define SHOW(...) static_cast<void>(0) int main() { using mint = modint<1000000007>; const auto N = in.val<ll>(); std::map<ll, ll> mp; for (ll i = 1; i * i <= N; i++) { mp[i] = 0; mp[N / i] = 0; } for (auto& [x, n] : mp) { n = N / x - N / (x + 1); } const int n = mp.size(); auto ord = [&](const ll x) -> int { if (x * x <= N) { return x - 1; } return n - (N / x); }; auto f = [&](const ll X) { std::map<ll, ll> mp; for (ll i = 1; i * i <= X; i++) { mp[i] = 0; mp[X / i] = 0; } for (auto& [x, n] : mp) { n = X / x - X / (x + 1); } mint ans = 0; for (const auto& [x, n] : mp) { ans += x * n; } return ans; }; mint S1 = -N; for (const auto& [x, n] : mp) { S1 += mint(x) * n; } S1 *= (N - 2); mint S2 = 0; for (const auto& [x, n] : mp) { S2 += mint(x - 1) * (x - 2) * n; } mint S3 = 0; ll n3 = 0; for (; n3 * n3 * n3 <= N; n3++) {} n3--; SHOW(n3); for (ll i = 1; i <= n3; i++) { const ll X = N / i; S3 += f(X); SHOW(S3); for (ll j = 1; j <= n3; j++) { S3 -= N / (i * j); } SHOW(S3); } S3 *= 3; S3 += n3 * n3 * n3; SHOW(N, f(N)); SHOW(S3); S3 -= 2 * f(N); S3 += N; out.ln(S1 - S2 - S3); // auto F = [&](const ll N) { // ll ans = 0; // for (ll a = 1; a <= N; a++) { // for (ll b = a; b <= N; b += a) { ans += N / b; } // } // return ans; // // out.ln(ans); // }; // std::vector<ll> vs; // for (int i = 1; i <= 100; i++) { vs.push_back(F(i)); } // SHOW(vs); return 0; }