QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#739901 | #9619. 乘积,欧拉函数,求和 | Nightsky | WA | 118ms | 4828kb | C++14 | 1.9kb | 2024-11-12 23:49:09 | 2024-11-12 23:49:10 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 3e3 + 5;
const int MOD = 998244353;
vector <int> prime;
int A[MAXN],n,sta[MAXN],id[MAXN];
ll f[2][(1<<16)+5];
bool isprime[MAXN];
ll qpw(ll x,ll b)
{
ll ans = 1;
while(b)
{
if(b&1) ans = ans * x % MOD;
x = x * x % MOD;
b >>= 1;
}
return ans;
}
int main()
{
int upperbound = sqrt(3000);
for(int i = 2; i <= 3000; ++i)
{
if(isprime[i]) continue;
if(i < upperbound)
{
id[i] = prime.size();
prime.push_back(i);
}
for(int j = i + i; j <= 3000; j += i)
isprime[j] = 1;
}
scanf("%d",&n);
map <int,vector<int>> mp;
for(int i = 1; i <= n; ++i)
{
scanf("%d",&A[i]);
int tmp = A[i];
for(int p:prime)
{
if(A[i] % p == 0) sta[i] |= (1 << id[p]);
while(tmp % p == 0) tmp /= p;
}
mp[tmp].push_back(i);
}
f[0][0] = 1;
for(auto [p,vec] : mp)
{
for(int i : vec)
{
for(int s = (1<<16) - 1; s >= 0; --s)
{
int ts = s ^ sta[i];
f[1][ts] = (f[1][ts] + f[0][s] * A[i] + f[1][s] * A[i]) % MOD;
}
}
ll inv = qpw(p,MOD-2);
for(int s = (1<<16) - 1; s >= 0; --s)
{
if(p != 1) f[1][s] = f[1][s] * inv % MOD * (p-1) % MOD;
f[0][s] = (f[0][s] + f[1][s]) % MOD;
}
memset(f[1],0,sizeof f[1]);
}
ll ans = 0;
for(int s = 0; s < (1<<16); ++s)
{
for(int i = 0; i < 16; ++i)
{
ll inv = qpw(prime[i],MOD-2);
if((1<<i) & s) f[0][s] = f[0][s] * inv % MOD * (prime[i]-1) % MOD;
}
ans = (ans + f[0][s]) % MOD;
}
printf("%lld\n",ans);
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 118ms
memory: 4828kb
input:
5 1 6 8 6 2
output:
103508
result:
wrong answer 1st lines differ - expected: '892', found: '103508'