QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#750951#9619. 乘积,欧拉函数,求和mitthuWA 738ms5256kbC++172.1kb2024-11-15 16:28:402024-11-15 16:28:41

Judging History

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

  • [2024-11-15 16:28:41]
  • 评测
  • 测评结果:WA
  • 用时:738ms
  • 内存:5256kb
  • [2024-11-15 16:28:40]
  • 提交

answer

#include<bits/stdc++.h>
const int mo = 998244353;
const int maxm = 3e3 + 5; 
const int maxn = 2e3 + 5;
const int maxk = 1 << 16;
using namespace std;
int n, a[maxn], st[maxn], m, val[maxm], lim = (1 << 16), sum[maxk], inv[20];
int prime[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
int f[3][maxk], g[3][maxk];
vector<int>t[maxm];
int div(int x){
    for (int i = 0; i <= 15; i++)
        while(x % prime[i] == 0) x /= prime[i];
    return x;
}
int ksm(int x, int y){
    int res = 1;
    for (; y; y >>= 1, x = 1LL * x * x %mo)if (y & 1) res = 1LL * res * x % mo;
    return res;
}
int main(){
    for (int i = 0; i < 16; i++)inv[i] = ksm(prime[i], mo - 2);
    for (int i = 0; i < lim; i++){
        sum[i] = 1;
        for (int j = 0; j < 16; j++)
            if (i >> j & 1)
                sum[i] = 1LL * sum[i] * inv[j] % mo * (prime[j] - 1) % mo;
    }
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        int num = div(a[i]);
        for (int j = 0; j < 16; j++)
            if (a[i] % prime[j] == 0) val[a[i]] |= 1 << j;
        t[num].push_back(a[i]);
        st[++m] = num;
    }
    sort(st + 1, st + m + 1); m = unique(st + 1, st + m + 1) - st - 1;
    int cnt = 0;
    f[0][0] = 1;
    for (int i = 1; i <= m; i++){
        int P = (st[i] == 1) ? 1 : 1LL * (st[i] - 1) * ksm(st[i], mo - 2) % mo;
        for (int j = 0; j < lim; j++) g[0][j] = g[1][j] = 0;
        for (auto x: t[i]){
            int num = (++cnt) & 1;
            for (int j = 0; j < lim; j++)f[num][j] = f[num ^ 1][j], g[num][j] = g[num ^ 1][j];
            for (int j = 0; j < lim; j++){
                int k = j | val[x];
                g[num][k] = (g[num][k] + 1LL * f[num ^ 1][j] * x % mo * P % mo) % mo;
                g[num][k] = (g[num][k] + 1LL * g[num ^ 1][j] * x % mo) % mo;
            }
        } 
        int num = cnt & 1;
        for (int j = 0; j < lim; j++)f[num][j] = (f[num][j] + g[num][j]) % mo, g[num][j] = 0;     
    }
    int ans = 0;
    for (int i = 0; i < lim; i++)
        ans = (ans + 1LL * f[n & 1][i] * sum[i] % mo) % mo;
    printf("%d\n", ans);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 5256kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 8ms
memory: 5196kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 738ms
memory: 5232kb

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:

891502416

result:

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