結果
問題 | No.3079 アルベド |
ユーザー | a01sa01to |
提出日時 | 2024-12-07 00:29:19 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,441 bytes |
コンパイル時間 | 4,022 ms |
コンパイル使用メモリ | 263,460 KB |
実行使用メモリ | 13,824 KB |
最終ジャッジ日時 | 2024-12-07 00:29:49 |
合計ジャッジ時間 | 29,992 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | TLE | - |
ソースコード
#line 1 "main.cpp" #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; #line 2 "my-library\\library\\math\\meissel-lehmer.hpp" #line 4 "my-library\\library\\math\\meissel-lehmer.hpp" #include <concepts> #line 7 "my-library\\library\\math\\meissel-lehmer.hpp" using namespace std; #line 2 "my-library\\library\\data-structure\\bit.hpp" #line 4 "my-library\\library\\data-structure\\bit.hpp" using namespace std; #line 2 "my-library\\library\\_internal\\types.hpp" #line 4 "my-library\\library\\_internal\\types.hpp" #include <type_traits> using namespace std; #line 2 "my-library\\library\\_internal\\modint-base.hpp" #line 5 "my-library\\library\\_internal\\modint-base.hpp" using namespace std; namespace asalib { namespace _internal { class modint_base {}; template<typename T> concept is_modint = is_base_of_v<modint_base, T>; } } #line 8 "my-library\\library\\_internal\\types.hpp" namespace asalib { namespace _internal { template<class T> concept integral_like = integral<T> || is_modint<T>; template<class T> concept floating_like = floating_point<T>; template<class T> concept numeric_like = integral_like<T> || floating_like<T>; template<class T> T plus(T a, T b) { return a + b; } template<class T> T minus(T a, T b) { return a - b; } template<class T> T zero() { return 0; } } } #line 7 "my-library\\library\\data-structure\\bit.hpp" namespace asalib { namespace ds { template<_internal::numeric_like T, T (*op)(T, T) = _internal::plus<T>, T (*invop)(T, T) = _internal::minus<T>, T (*e)() = _internal::zero<T>> class BIT { public: BIT(): _n(0) {} explicit BIT(size_t n) { _n = n; data.reserve(n); data.resize(n, 0); } void add(size_t i, T x) { assert(0 <= i && i < _n); ++i; while (i <= _n) { data[i - 1] = op(data[i - 1], x); i += i & -i; } } T sum(size_t l, size_t r) const { assert(0 <= l && l <= r && r <= _n); return invop(_sum(r), _sum(l)); } private: size_t _n; vector<T> data; T _sum(size_t i) const { T s = e(); while (i > 0) { s = op(s, data[i - 1]); i -= i & -i; } return s; } }; } } #line 10 "my-library\\library\\math\\meissel-lehmer.hpp" namespace asalib { namespace math { template<integral T> constexpr T meissel_lehmer(T n) { if (n <= 2) [[unlikely]] return n == 2; T y = powl(n, 1.0 / 3.0) * powl(logl(n), 2.0 / 3.0); T ny = n / y; if (n < 200) [[unlikely]] ny = n; constexpr T None = -1; vector<T> minim_prime(ny + 1, None); vector<T> prime(0); for (T i = 2; i <= ny; ++i) { if (minim_prime[i] == None) { minim_prime[i] = prime.size(); prime.push_back(i); } for (T j = 0; j < (T) prime.size(); ++j) { if (i * prime[j] > ny || prime[j] > prime[minim_prime[i]]) break; minim_prime[i * prime[j]] = j; } } if (n < 200) [[unlikely]] return prime.size(); T pi_ny = prime.size(); T pi_y = 0; for (T p : prime) { if (p > y) break; ++pi_y; } T pi_n = pi_y - 1; for (T b = pi_y + 1, c = pi_ny; b <= pi_ny; ++b) { while (c >= b && prime[b - 1] * prime[c - 1] > n) --c; if (c < b) break; pi_n -= c - b + 1; } vector<tuple<T, T, bool>> params(0); function<void(T, T, bool)> phi = [&](T x, T a, bool isMinus) { if (x == 0) return; else if (x <= ny) params.push_back({ x, a, isMinus }); else if (a == 0) pi_n += x * (isMinus ? -1 : 1); else phi(x, a - 1, isMinus), phi(x / prime[a - 1], a - 1, !isMinus); }; phi(n, pi_y, false); sort(params.begin(), params.end()); asalib::ds::BIT<T> bit(pi_ny); T idx = 2; for (auto&& [n, a, isMinus] : params) { while (idx <= n) bit.add(minim_prime[idx++], 1); pi_n += (n - bit.sum(0, a)) * (isMinus ? -1 : 1); } return pi_n; } } } #line 8 "main.cpp" int main() { int t; cin >> t; while (t--) { int n; cin >> n; cout << asalib::math::meissel_lehmer(n) << endl; } return 0; }