QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744754 | #9619. 乘积,欧拉函数,求和 | BaseAI | TL | 1727ms | 7584kb | C++23 | 3.3kb | 2024-11-13 23:10:44 | 2024-11-13 23:10:45 |
Judging History
answer
#include<bits/stdc++.h>
// #define int long long
using namespace std;
const int N = 3007;
const int mod = 998244353;
int n;
vector<int> P;
bool visP[N];
void InitPrime() {
visP[1] = 1;
for(int i=2;i<N;++i) {
if(!visP[i]) P.push_back(i);
for(auto p : P) {
if(p*i >= N) break;
visP[p * i] = 1;
if(i%p == 0) break;
}
}
}
typedef pair<int,int> pii;
#define mp make_pair
int xcnt[N][16];
vector<pair<pii,int>> vec[N];
int MaxFac(int x,int &s,int id) {
for(int i=0;i<16;++i) {
auto p = P[i];
if(x%p == 0) s |= (1 << i);
while(x%p == 0) x /= p, ++xcnt[id][i];
}
return x;
}
const int M = 16;
const int S = (1<<M);
int f[2][S][2];
int& add(int &x,int y) {
if(x+y>=mod)
{
x=x+y-mod;
}
else
{
x=x+y;
}
return x;
}
int& mul(int &x,int y) {
return x = (long long)x * y % mod;
}
/*int Pow(int x,int y) {
if(y <= 0) return 1;
int res = 1, base = x;
while(y) {
if(y&1) res = res*base % mod;
base = base*base % mod;
y >>= 1;
}
return res;
}*/
const int MAXN=4e4+3;
int Pow[16][MAXN];
void InitPow() {
for(int i=0;i<16;++i) {
Pow[i][0] = 1;
for(int j=1;j<MAXN;++j) {
Pow[i][j] = (long long)Pow[i][j-1] * P[i] % mod;
}
}
}
void solve() {
InitPow();
cin >> n;
vector<int> a(n);
for(int i=0;i<n;++i) cin >> a[i];
set<int> st;
for(int i=0;i<n;i++) {
auto x=a[i];
int s = 0;
int fac = MaxFac(x, s, i);
vec[fac].push_back(mp(mp(x, s), i));
st.insert(fac);
}
int now = 1, last = 0;
f[last][0][1] = 1;
for(auto y : st) {
for(int s=0;s<S;++s) {
add(f[last][s][0], f[last][s][1]);
f[last][s][1] = 0;
}
//cout << "test:: " << f[last][0][0] << "\n";
for(auto [tmp,id] : vec[y]) {
auto [x,xs]=tmp;
for(int s=0;s<S;++s) {
f[now][s][0] = f[last][s][0];
f[now][s][1] = f[last][s][1];
}
for(int s=0;s<S;++s) {
int fir = xs & (xs^s);
int sec = xs & (s);
int val = 1;
for(int j=0;j<16;++j) {
if(!(xs&(1<<j)))continue;
if(fir & (1<<j)) mul(val, P[j]-1);
if(sec & (1<<j)) mul(val, P[j]);
//val = val*Pow(P[j], xcnt[j]-1);
if(xcnt[id][j] >= 2) mul(val, Pow[j][xcnt[id][j]-1]);
//if((fir & (1ll<<j) )==(sec & (1ll<<j)) && ((fir & (1ll<<j)) == 1)) cout << "wa" << "\n";
}
add(f[now][s|xs][1], mul(mul(f[last][s][0], val), max(1, y-1)) );
add(f[now][s|xs][1], mul(mul(f[last][s][1], val), y) );
}
now ^= 1, last ^= 1;
}
}
int ans = 0;
for(int s=0;s<S;++s) {
//cout << f[last][s][0] << " " << f[last][s][1] << "\n";
add(ans, add(f[last][s][0],f[last][s][1]));
}
cout << ans << "\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
InitPrime();
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 7392kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 10ms
memory: 7360kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: 0
Accepted
time: 1709ms
memory: 7532kb
input:
2000 79 1 1 1 1 1 1 2803 1 1 1 1 1 1 1609 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2137 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 613 1 499 1 211 1 2927 1 1 1327 1 1 1123 1 907 1 2543 1 1 1 311 2683 1 1 1 1 2963 1 1 1 641 761 1 1 1 1 1 1 1 1 1 1 1 1489 2857 1 1 1 1 1 1 1 1 1 1 1 1 1 967 1 821 1 1 1 1 2143 1861...
output:
50965652
result:
ok single line: '50965652'
Test #4:
score: 0
Accepted
time: 1727ms
memory: 7584kb
input:
2000 1 1 1 1 1 1 1 1 353 1 1 1 557 1 1 1 1 1 1 1 1 1 1 1 1423 1 1 1327 1 1 1 907 1 1 1 1 1 2971 1 1 1 2531 1 1 1 1 1 1 1 1 1 2099 1 1 1 1 1 1 1 1 1 1 1 1 1 1 199 2999 1 727 1 1 1 1 1 1 1 71 1 1 1 1 1 1 2503 1 176 1 1 1 1 1 1 1361 1013 1 1 1 1 1 1 1 2699 1 1 1 1 1 1 1 1 1 2897 1 1 1 1 1637 1 1 1367 1...
output:
420709530
result:
ok single line: '420709530'
Test #5:
score: 0
Accepted
time: 32ms
memory: 7268kb
input:
30 37 14 35 33 38 42 46 3 26 7 16 1 35 38 48 3 43 49 18 3 29 1 43 43 20 6 39 20 14 38
output:
262613273
result:
ok single line: '262613273'
Test #6:
score: 0
Accepted
time: 38ms
memory: 7160kb
input:
30 39 31 49 2 4 28 30 12 13 34 7 28 17 37 38 18 41 33 29 36 18 7 3 14 30 42 35 14 18 35
output:
234142118
result:
ok single line: '234142118'
Test #7:
score: 0
Accepted
time: 222ms
memory: 7180kb
input:
200 53 37 234 248 66 30 64 181 38 130 250 27 199 226 43 185 207 241 38 296 68 18 145 20 64 127 57 30 168 267 221 116 115 192 17 26 5 63 3 127 52 48 229 58 69 111 20 244 234 35 48 217 179 189 89 60 285 106 43 104 36 28 62 281 104 38 281 264 140 275 105 20 203 271 222 262 123 10 82 263 118 254 229 222...
output:
617035263
result:
ok single line: '617035263'
Test #8:
score: 0
Accepted
time: 220ms
memory: 7120kb
input:
200 119 128 228 63 117 123 211 147 116 286 29 252 5 216 146 224 220 103 78 269 12 53 245 121 123 139 210 132 122 207 9 46 265 128 167 171 207 120 99 135 27 9 111 192 228 295 33 156 151 59 240 90 2 254 36 58 168 228 220 57 154 268 20 244 272 71 207 290 132 231 115 277 97 32 28 184 172 24 198 218 79 8...
output:
942938793
result:
ok single line: '942938793'
Test #9:
score: -100
Time Limit Exceeded
input:
2000 1516 1151 2408 2818 654 542 743 2216 777 1267 279 2373 605 367 2837 1608 2611 2315 883 2309 1185 832 1850 1696 1774 269 2448 2397 163 2223 715 1845 2805 467 519 585 323 517 1792 2206 2125 2984 1019 1777 193 972 1804 2408 2954 1155 1217 1959 1647 553 2716 2591 982 2776 1687 1504 2753 333 1803 23...