結果
| 問題 | No.732 3PrimeCounting |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-08 14:37:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 5,450 bytes |
| コンパイル時間 | 861 ms |
| コンパイル使用メモリ | 92,064 KB |
| 最終ジャッジ日時 | 2024-11-14 21:56:18 |
| 合計ジャッジ時間 | 1,732 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:16:39: error: '::numeric_limits' has not been declared
16 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
| ^~~~~~~~~~~~~~
main.cpp:16:55: error: expected primary-expression before '>' token
16 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
| ^
main.cpp:16:61: error: no matching function for call to 'max()'
16 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
| ~~~~~^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:50,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39,
from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
254 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: template argument deduction/substitution failed:
main.cpp:16:61: note: candidate expects 2 arguments, 0 provided
16 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
| ~~~~~^~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:300:5: note: candidate: 'templat
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
vector<int> get_prime(int n){
if(n <= 1) return vector<int>();
vector<bool> is_prime(n+1, true);
vector<int> prime;
is_prime[0] = is_prime[1] = 0;
for (int i = 2; i <= n; ++i) {
if(is_prime[i]) prime.emplace_back(i);
for (auto &&j : prime){
if(i*j > n) break;
is_prime[i*j] = false;
if(i % j == 0) break;
}
}
return prime;
}
constexpr int ntt_mod = 998244353, ntt_root = 3;
// 1012924417 -> 5, 924844033 -> 5
// 998244353 -> 3, 897581057 -> 3
// 645922817 -> 3;
template<int M, int proot>
class NTT {
vector<vector<int>> rts, rrts;
public:
NTT() = default;
inline int add(int a,int b){ a += b; if(a >= M) a -= M; return a; }
inline int mul(int a,int b){ return 1LL * a * b % M; }
inline int pow(int a,int b){
int res = 1;
while(b){
if(b&1) res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
inline int extgcd(int a, int b, int &x ,int &y){
for (int u = y = 1, v = x = 0; a; ) {
ll q = b/a;
swap(x -= q*u, u);
swap(y -= q*v, v);
swap(b -= q*a, a);
}
return b;
}
inline int inv(int x){
int s, t;
extgcd(x, M, s, t);
return (M+s)%M;
}
void ensure_base(int N) {
if(rts.size() >= N) return;
rts.resize(N), rrts.resize(N);
for(int i = 1; i < N; i <<= 1) {
if(!rts[i].empty()) continue;
int w = pow(proot, (M - 1) / (i << 1));
int rw = inv(w);
rts[i].resize(i), rrts[i].resize(i);
rts[i][0] = 1, rrts[i][0] = 1;
for(int k = 1; k < i; k++) {
rts[i][k] = mul(rts[i][k - 1],w);
rrts[i][k] = mul(rrts[i][k - 1],rw);
}
}
}
void ntt(vector<int> &a, int sign){
int n = a.size();
ensure_base(n);
for (int i = 0, j = 1; j < n-1; ++j) {
for (int k = n >> 1; k > (i ^= k); k >>= 1);
if(j < i) swap(a[i], a[j]);
}
for (int i = 1; i < n; i <<= 1) {
for (int j = 0; j < n; j += i * 2) {
for (int k = 0; k < i; ++k) {
int y = mul(a[j+k+i], (sign ? rrts[i][k] : rts[i][k]));
a[j+k+i] = add(a[j+k], M-y), a[j+k] = add(a[j+k], y) ;
}
}
}
if(sign) {
int temp = inv(n);
for (int i = 0; i < n; ++i) a[i] = mul(a[i],temp);
}
}
};
NTT<ntt_mod, ntt_root> ntt;
constexpr int M = ntt_mod;
struct poly {
vector<int> v;
poly() = default;
explicit poly(int n) : v(n) {};
explicit poly(vector<int> vv) : v(std::move(vv)) {};
int size() const {return (int)v.size(); }
poly cut(int len){
if(len < v.size()) v.resize(static_cast<unsigned long>(len));
return *this;
}
inline int& operator[] (int i) {return v[i]; }
poly operator+(const poly &a) const { return poly(*this) += a; }
poly operator-(const poly &a) const { return poly(*this) -= a; }
poly operator*(const poly &a) const { return poly(*this) *= a; }
poly inv() const {
int n = size();
vector<int> rr(1, ntt.inv(this->v[0]));
poly r(rr);
for (int k = 2; k <= n; k <<= 1) {
vector<int> u(k);
for (int i = 0; i < k; ++i) {
u[i] = this->v[i];
}
poly ff(u);
poly nr = (r*r);
nr = nr*ff;
nr.cut(k);
for (int i = 0; i < k/2; ++i) {
nr[i] = (2*r[i]-nr[i]+M)%M;
nr[i+k/2] = (M-nr[i+k/2])%M;
}
r = nr;
}
r.v.resize(n);
return r;
}
poly& operator+=(const poly &a) {
this->v.resize(max(size(), a.size()));
for (int i = 0; i < a.size(); ++i) {
(this->v[i] += a.v[i]);
if(this->v[i] > ntt_mod) this->v[i] -= M;
}
return *this;
}
poly& operator-=(const poly &a) {
this->v.resize(max(size(), a.size()));
for (int i = 0; i < a.size(); ++i) {
(this->v[i] += M-a.v[i]);
if(this->v[i] > M) this->v[i] -= M;
}
return *this;
}
poly& operator*=(poly a) {
int N = size()+a.size()-1;
int sz = 1;
while(sz < N) sz <<= 1;
ntt.ensure_base(sz);
this->v.resize(sz); a.v.resize(sz);
ntt.ntt(this->v, 0); ntt.ntt(a.v, 0);
for(int i = 0; i < sz; ++i) this->v[i] = ntt.mul(this->v[i], a.v[i]);
ntt.ntt(this->v, 1);
return *this;
}
poly& operator/=(const poly &a){
return (*this *= a.inv());
}
};
int main() {
int n;
cin >> n;
auto p = get_prime(3*n);
poly A(n+1), B(2*n+1);
for (auto &&i : p) {
if(i > n) continue;
A[i]++;
B[2*i] += 3;
}
poly ret = (A*A-B)*A;
ll ans = 0;
for (auto &&i : p) {
ans += ret[i]/6;
}
cout << ans << "\n";
return 0;
}