QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751241#9619. 乘积,欧拉函数,求和ucup-team2179#WA 426ms5288kbC++202.0kb2024-11-15 17:41:152024-11-15 17:41:16

Judging History

你现在查看的是最新测评结果

  • [2024-11-15 17:41:16]
  • 评测
  • 测评结果:WA
  • 用时:426ms
  • 内存:5288kb
  • [2024-11-15 17:41:15]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define db double
#define pii pair<int, int>
#define ll long long
using namespace std;
const int N = 3333, maxn = (1 << 16) + 99, mod = 998244353;
int p[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
int a[N], st[N], inv[N];
int f[maxn], n, g[2][maxn];
vector<int> v[N];
void solve() {
    inv[1] = 1;
    for (int i = 2; i <= 3000; i++)
        inv[i] = mod - mod / i * inv[mod % i] % mod;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        int x = a[i];
        for (int j = 0; j < 16; j++){
            if(a[i] % p[j] == 0){
                st[i] |= (1 << j);
                while(a[i] % p[j] == 0)
                    a[i] /= p[j];
            }
        }
        v[a[i]].push_back(i);
        a[i] = x;
    }
    f[0] = 1;
    for (int i = 1; i <= 3000; i++){
        if(v[i].size() == 0)
            continue;
        int now = 0;
        for(auto id : v[i]){
            now ^= 1;
            for(int j = 0; j < (1 << 16); j++)
                g[now][j] = g[now ^ 1][j];
            for (int j = 0; j < (1 << 16); j++){
                g[now][j | st[id]] = (f[j] * a[id] + g[now][j | st[id]]) % mod;
                g[now][j | st[id]] = (g[now][j | st[id]] + g[now ^ 1][j] * a[id]) % mod;
            }
        }
        for (int j = 0; j < (1 << 16); j++){
            if(i != 1)
                f[j] = (f[j] + g[now][j] * inv[i] % mod * (i - 1)) % mod;
            else
                f[j] = (f[j] + g[now][j]) % mod;
            g[0][j] = g[1][j] = 0;
        }
    }
    int ans = 0;
    for (int i = 0; i < (1 << 16); i++){
        for (int j = 0; j < 16; j++)
             if((i >> j) & 1){
                 f[i] = f[i] * inv[p[j]] % mod * (p[j] - 1);
             }
        ans = (ans + f[i]) % mod;
    }
    cout << ans << '\n';
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 5080kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 3ms
memory: 5132kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 426ms
memory: 5288kb

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:

-898765943

result:

wrong answer 1st lines differ - expected: '50965652', found: '-898765943'