提出 #67788566
ソースコード 拡げる
// #include <bits/allocator.h> // Temp fix for gcc13 global pragma
// #pragma GCC target("avx2,bmi2,popcnt,lzcnt")
// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif
#ifdef LOCAL
#include "Debug.h"
#else
#define debug_endl() 42
#define debug(...) 42
#define debug2(...) 42
#define debug_bin(...) 42
#endif
template<class data_t, data_t _mod>
struct modular_fixed_base{
#define IS_INTEGRAL(T) (is_integral_v<T> || is_same_v<T, __int128_t> || is_same_v<T, __uint128_t>)
#define IS_UNSIGNED(T) (is_unsigned_v<T> || is_same_v<T, __uint128_t>)
static_assert(IS_UNSIGNED(data_t));
static_assert(1 <= _mod && _mod < data_t(1) << 8 * sizeof(data_t) - 1);
static constexpr bool VARIATE_MOD_FLAG = false;
static constexpr data_t mod(){
return _mod;
}
template<class T>
static constexpr vector<modular_fixed_base> precalc_power(T base, int SZ){
vector<modular_fixed_base> res(SZ + 1, 1);
for(auto i = 1; i <= SZ; ++ i) res[i] = res[i - 1] * base;
return res;
}
template<class T>
static constexpr vector<modular_fixed_base> precalc_geometric_sum(T base, int SZ){
vector<modular_fixed_base> res(SZ + 1);
for(auto i = 1; i <= SZ; ++ i) res[i] = res[i - 1] * base + base;
return res;
}
static vector<modular_fixed_base> _INV;
static constexpr void precalc_inverse(int SZ){
if(_INV.empty()) _INV.assign(2, 1);
for(auto x = _INV.size(); x <= SZ; ++ x) _INV.push_back(_mod / x * -_INV[_mod % x]);
}
// _mod must be a prime
static modular_fixed_base _primitive_root;
static constexpr modular_fixed_base primitive_root(){
if(_primitive_root) return _primitive_root;
if(_mod == 2) return _primitive_root = 1;
if(_mod == 998244353) return _primitive_root = 3;
data_t divs[20] = {};
divs[0] = 2;
int cnt = 1;
data_t x = (_mod - 1) / 2;
while(x % 2 == 0) x /= 2;
for(auto i = 3; 1LL * i * i <= x; i += 2){
if(x % i == 0){
divs[cnt ++] = i;
while(x % i == 0) x /= i;
}
}
if(x > 1) divs[cnt ++] = x;
for(auto g = 2; ; ++ g){
bool ok = true;
for(auto i = 0; i < cnt; ++ i){
if(modular_fixed_base(g).power((_mod - 1) / divs[i]) == 1){
ok = false;
break;
}
}
if(ok) return _primitive_root = g;
}
}
constexpr modular_fixed_base(){ }
constexpr modular_fixed_base(const double &x){ _data = _normalize(llround(x)); }
constexpr modular_fixed_base(const long double &x){ _data = _normalize(llround(x)); }
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr> constexpr modular_fixed_base(const T &x){ _data = _normalize(x); }
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr> static constexpr data_t _normalize(const T &x){
int sign = x >= 0 ? 1 : -1;
data_t v = _mod <= sign * x ? sign * x % _mod : sign * x;
if(sign == -1 && v) v = _mod - v;
return v;
}
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr> constexpr operator T() const{ return data(); }
constexpr modular_fixed_base &operator+=(const modular_fixed_base &otr){ if((_data += otr._data) >= _mod) _data -= _mod; return *this; }
constexpr modular_fixed_base &operator-=(const modular_fixed_base &otr){ if((_data += _mod - otr._data) >= _mod) _data -= _mod; return *this; }
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr> constexpr modular_fixed_base &operator+=(const T &otr){ return *this += modular_fixed_base(otr); }
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr> constexpr modular_fixed_base &operator-=(const T &otr){ return *this -= modular_fixed_base(otr); }
constexpr modular_fixed_base &operator++(){ return *this += 1; }
constexpr modular_fixed_base &operator--(){ return *this += _mod - 1; }
constexpr modular_fixed_base operator++(int){ modular_fixed_base result(*this); *this += 1; return result; }
constexpr modular_fixed_base operator--(int){ modular_fixed_base result(*this); *this += _mod - 1; return result; }
constexpr modular_fixed_base operator-() const{ return modular_fixed_base(_mod - _data); }
constexpr modular_fixed_base &operator*=(const modular_fixed_base &rhs){
if constexpr(is_same_v<data_t, unsigned int>) _data = (unsigned long long)_data * rhs._data % _mod;
else if constexpr(is_same_v<data_t, unsigned long long>){
long long res = _data * rhs._data - _mod * (unsigned long long)(1.L / _mod * _data * rhs._data);
_data = res + _mod * (res < 0) - _mod * (res >= (long long)_mod);
}
else _data = _normalize(_data * rhs._data);
return *this;
}
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>
constexpr modular_fixed_base &inplace_power(T e){
if(e == 0) return *this = 1;
if(_data == 0) return *this = {};
if(_data == 1 || e == 1) return *this;
if(_data == mod() - 1) return e % 2 ? *this : *this = -*this;
if(e < 0) *this = 1 / *this, e = -e;
if(e == 1) return *this;
modular_fixed_base res = 1;
for(; e; *this *= *this, e >>= 1) if(e & 1) res *= *this;
return *this = res;
}
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>
constexpr modular_fixed_base power(T e) const{
return modular_fixed_base(*this).inplace_power(e);
}
// c + c * x + ... + c * x^{e-1}
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>
constexpr modular_fixed_base &inplace_geometric_sum(T e, modular_fixed_base c = 1){
if(e == 0) return *this = {};
if(_data == 0) return *this = {};
if(_data == 1) return *this = c * e;
if(e == 1) return *this = c;
if(_data == mod() - 1) return *this = c * abs(e % 2);
modular_fixed_base res = 0;
if(e < 0) return *this = geometric_sum(-e + 1, -*this) - 1;
if(e == 1) return *this = c * *this;
for(; e; c *= 1 + *this, *this *= *this, e >>= 1) if(e & 1) res += c, c *= *this;
return *this = res;
}
// c + c * x + ... + c * x^{e-1}
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>
constexpr modular_fixed_base geometric_sum(T e, modular_fixed_base c = 1) const{
return modular_fixed_base(*this).inplace_geometric_sum(e, c);
}
// Returns the minimum integer e>0 with b^e=*this, if it exists
// O(sqrt(mod)) applications of hashmap
constexpr optional<data_t> log(const modular_fixed_base &b) const{
data_t m = mod(), n = sqrtl(m) + 1, j = 1;
modular_fixed_base e = 1, f = 1;
unordered_map<data_t, data_t> A;
while(j <= n && (f = e *= b) != *this) A[(e * *this).data()] = j ++;
if(e == *this) return j;
if(gcd(mod(), e.data()) == gcd(mod(), data())) for(auto i = 2; i < n + 2; ++ i) if(A.count((e *= f).data())) return n * i - A[e.data()];
return {};
}
constexpr optional<modular_fixed_base> inverse() const{
make_signed_t<data_t> a = data(), m = _mod, u = 0, v = 1;
if(data() < _INV.size()) return _INV[data()];
while(a){
make_signed_t<data_t> t = m / a;
m -= t * a; swap(a, m);
u -= t * v; swap(u, v);
}
if(m != 1) return {};
return modular_fixed_base{u};
}
modular_fixed_base &operator/=(const modular_fixed_base &otr){
auto inv_ptr = otr.inverse();
assert(inv_ptr);
return *this = *this * *inv_ptr;
}
#define ARITHMETIC_OP(op, apply_op)\
constexpr modular_fixed_base operator op(const modular_fixed_base &x) const{ return modular_fixed_base(*this) apply_op x; }\
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>\
constexpr modular_fixed_base operator op(const T &x) const{ return modular_fixed_base(*this) apply_op modular_fixed_base(x); }\
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>\
constexpr friend modular_fixed_base operator op(const T &x, const modular_fixed_base &y){ return modular_fixed_base(x) apply_op y; }
ARITHMETIC_OP(+, +=) ARITHMETIC_OP(-, -=) ARITHMETIC_OP(*, *=) ARITHMETIC_OP(/, /=)
#undef ARITHMETIC_OP
#define COMPARE_OP(op)\
constexpr bool operator op(const modular_fixed_base &x) const{ return _data op x._data; }\
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>\
constexpr bool operator op(const T &x) const{ return _data op modular_fixed_base(x)._data; }\
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>\
constexpr friend bool operator op(const T &x, const modular_fixed_base &y){ return modular_fixed_base(x)._data op y._data; }
COMPARE_OP(==) COMPARE_OP(!=) COMPARE_OP(<) COMPARE_OP(<=) COMPARE_OP(>) COMPARE_OP(>=)
#undef COMPARE_OP
friend istream &operator>>(istream &in, modular_fixed_base &number){
long long x;
in >> x;
number._data = modular_fixed_base::_normalize(x);
return in;
}
friend ostream &operator<<(ostream &out, const modular_fixed_base &number){
out << number._data;
#ifdef LOCAL
cerr << "(";
for(auto d = 1; ; ++ d){
if((number * d)._data <= 1000000){
cerr << (number * d)._data;
if(d != 1) cerr << "/" << d;
break;
}
else if((-number * d)._data <= 1000000){
cerr << "-" << (-number * d)._data;
if(d != 1) cerr << "/" << d;
break;
}
}
cerr << ")";
#endif
return out;
}
data_t _data = 0;
constexpr data_t data() const{ return _data; }
#undef IS_INTEGRAL
#undef IS_UNSIGNED
};
template<class data_t, data_t _mod> vector<modular_fixed_base<data_t, _mod>> modular_fixed_base<data_t, _mod>::_INV;
template<class data_t, data_t _mod> modular_fixed_base<data_t, _mod> modular_fixed_base<data_t, _mod>::_primitive_root;
constexpr unsigned int mod = (119 << 23) + 1; // 998244353
// constexpr unsigned int mod = 1e9 + 7; // 1000000007
// constexpr unsigned int mod = 1e9 + 9; // 1000000009
// constexpr unsigned long long mod = (unsigned long long)1e18 + 9;
using modular = modular_fixed_base<decay_t<decltype(mod)>, mod>;
constexpr modular operator""_m(const char *x){
modular res = 0;
long long buffer = 0;
long long buffer_width = 1;
constexpr long long buffer_th = 1'000'000'000'000'000'000LL;
while(*x){
#ifdef LOCAL
assert(isdigit(*x));
#endif
buffer = buffer * 10 + (*(x ++) - '0');
if((buffer_width *= 10) == buffer_th){
res = buffer_width * res + buffer;
buffer = 0;
buffer_width = 1;
}
}
res = buffer_width * res + buffer;
return res;
}
struct number_theory{
int SZ;
vector<int> lpf, prime;
number_theory(int SZ): SZ(SZ), lpf(SZ + 1){ // O(SZ)
lpf[0] = lpf[1] = numeric_limits<int>::max() / 2;
for(auto i = 2; i <= SZ; ++ i){
if(!lpf[i]) lpf[i] = i, prime.push_back(i);
for(auto j = 0; j < (int)prime.size() && prime[j] <= lpf[i] && prime[j] * i <= SZ; ++ j) lpf[prime[j] * i] = prime[j];
}
}
vector<int> precalc_mobius() const{
vector<int> mobius(SZ + 1, 1);
for(auto i = 2; i <= SZ; ++ i){
if(i / lpf[i] % lpf[i]) mobius[i] = -mobius[i / lpf[i]];
else mobius[i] = 0;
}
return mobius;
}
vector<int> precalc_phi() const{
vector<int> phi(SZ + 1, 1);
for(auto i = 2; i <= SZ; ++ i){
if(i / lpf[i] % lpf[i]) phi[i] = phi[i / lpf[i]] * (lpf[i] - 1);
else phi[i] = phi[i / lpf[i]] * lpf[i];
}
return phi;
}
// Returns {gcd(0, n), ..., gcd(SZ, n)}
vector<int> precalc_gcd(int n) const{
vector<int> res(SZ + 1, 1);
res[0] = n;
for(auto x = 2; x <= SZ; ++ x) res[x] = n % (lpf[x] * res[x / lpf[x]]) ? res[x / lpf[x]] : lpf[x] * res[x / lpf[x]];
return res;
}
bool is_prime(int x) const{
assert(0 <= x && x <= SZ);
return lpf[x] == x;
}
int mu_large(long long x) const{ // O(sqrt(x))
int res = 1;
for(auto i = 2LL; i * i <= x; ++ i) if(x % i == 0){
if(x / i % i) return 0;
x /= i, res = -res;
}
if(x > 1) res = -res;
return res;
}
long long phi_large(long long x) const{ // O(sqrt(x))
long long res = x;
for(auto i = 2LL; i * i <= x; ++ i) if(x % i == 0){
while(x % i == 0) x /= i;
res -= res / i;
}
if(x > 1) res -= res / x;
return res;
}
// returns an array is_prime of length high-low where is_prime[i] = [low+i is a prime]
vector<int> sieve(long long low, long long high) const{
assert(high - 1 <= 1LL * SZ * SZ);
vector<int> is_prime(high - low, true);
for(auto p: prime) for(auto x = max(1LL * p, (low + p - 1) / p) * p; x < high; x += p) is_prime[x - low] = false;
for(auto x = 1; x >= low; -- x) is_prime[x - low] = false;
return is_prime;
}
};
int main(){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(ios::badbit | ios::failbit);
const int mx = 2e5;
vector<vector<int>> div(mx + 1);
for(auto x = 1; x <= mx; ++ x){
for(auto y = x; y <= mx; y += x){
div[y].push_back(x);
}
}
auto nt = number_theory(mx);
auto mu = nt.precalc_mobius();
auto power = modular::precalc_power(10, mx);
vector<modular> inv_power(mx + 1);
for(auto x = 1; x <= mx; ++ x){
inv_power[x] = 1 / -- power[x];
}
vector<modular> phi(mx + 1, 1);
for(auto d = 1; d <= mx; ++ d){
for(auto x = d; x <= mx; x += d){
if(!mu[x / d]){
continue;
}
phi[x] *= mu[x / d] == 1 ? power[d] : inv_power[d];
}
}
int n;
cin >> n;
modular res = 1;
vector<int> used(mx + 1);
for(auto i = 0; i < n; ++ i){
int x;
cin >> x;
for(auto d: div[x]){
if(!used[d]){
used[d] = true;
res *= phi[d];
}
}
cout << res / 9 << "\n";
}
return 0;
}
/*
*/
提出情報
| 提出日時 |
|
| 問題 |
C - Repunits |
| ユーザ |
FlowerOfSorrow |
| 言語 |
C++ 20 (gcc 12.2) |
| 得点 |
900 |
| コード長 |
13406 Byte |
| 結果 |
AC |
| 実行時間 |
148 ms |
| メモリ |
29348 KiB |
コンパイルエラー
Main.cpp: In instantiation of ‘struct modular_fixed_base<unsigned int, 998244353>’:
Main.cpp:222:45: required from here
Main.cpp:24:75: warning: suggest parentheses around ‘-’ inside ‘<<’ [-Wparentheses]
24 | static_assert(1 <= _mod && _mod < data_t(1) << 8 * sizeof(data_t) - 1);
| ~~~~~~~~~~~~~~~~~~~^~~
Main.cpp: In instantiation of ‘static constexpr data_t modular_fixed_base<data_t, _mod>::_normalize(const T&) [with T = int; typename std::enable_if<((is_integral_v<T> || is_same_v<T, __int128>) || is_same_v<T, __int128 unsigned>)>::type* <anonymous> = 0; data_t = unsigned int; data_t _mod = 998244353]’:
Main.cpp:78:133: required from here
Main.cpp:319:44: in ‘constexpr’ expansion of ‘modular_fixed_base<data_t, _mod>::precalc_power(T, int) [with T = int; data_t = unsigned int; data_t _mod = 998244353](((int)mx))’
Main.cpp:319:44: in ‘constexpr’ expansion of ‘modular_fixed_base<unsigned int, 998244353>(1)’
Main.cpp:81:34: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
81 | data_t v = _mod <= sign * x ? sign * x % _mod : sign * x;
| ~~~~~^~~~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
900 / 900 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_n_small_00.txt, 01_n_small_01.txt, 01_n_small_02.txt, 01_n_small_03.txt, 01_n_small_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 03_hcn_00.txt, 03_hcn_01.txt, 03_hcn_02.txt, 03_hcn_03.txt, 03_hcn_04.txt, 04_max_00.txt, 05_min_00.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
91 ms |
29184 KiB |
| 00_sample_01.txt |
AC |
93 ms |
29264 KiB |
| 00_sample_02.txt |
AC |
91 ms |
29232 KiB |
| 01_n_small_00.txt |
AC |
93 ms |
29168 KiB |
| 01_n_small_01.txt |
AC |
92 ms |
29260 KiB |
| 01_n_small_02.txt |
AC |
95 ms |
29164 KiB |
| 01_n_small_03.txt |
AC |
93 ms |
29264 KiB |
| 01_n_small_04.txt |
AC |
91 ms |
29200 KiB |
| 02_random_00.txt |
AC |
125 ms |
29348 KiB |
| 02_random_01.txt |
AC |
148 ms |
29208 KiB |
| 02_random_02.txt |
AC |
124 ms |
29224 KiB |
| 02_random_03.txt |
AC |
138 ms |
29192 KiB |
| 02_random_04.txt |
AC |
141 ms |
29200 KiB |
| 02_random_05.txt |
AC |
141 ms |
29228 KiB |
| 02_random_06.txt |
AC |
132 ms |
29204 KiB |
| 02_random_07.txt |
AC |
141 ms |
29192 KiB |
| 02_random_08.txt |
AC |
119 ms |
29176 KiB |
| 02_random_09.txt |
AC |
136 ms |
29112 KiB |
| 02_random_10.txt |
AC |
128 ms |
29192 KiB |
| 02_random_11.txt |
AC |
140 ms |
29220 KiB |
| 02_random_12.txt |
AC |
139 ms |
29268 KiB |
| 02_random_13.txt |
AC |
147 ms |
29288 KiB |
| 02_random_14.txt |
AC |
146 ms |
29188 KiB |
| 03_hcn_00.txt |
AC |
138 ms |
29288 KiB |
| 03_hcn_01.txt |
AC |
135 ms |
29288 KiB |
| 03_hcn_02.txt |
AC |
137 ms |
29180 KiB |
| 03_hcn_03.txt |
AC |
135 ms |
29284 KiB |
| 03_hcn_04.txt |
AC |
135 ms |
29220 KiB |
| 04_max_00.txt |
AC |
121 ms |
29232 KiB |
| 05_min_00.txt |
AC |
91 ms |
29192 KiB |