QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#745224 | #9619. 乘积,欧拉函数,求和 | yhddd | WA | 349ms | 4384kb | C++14 | 1.7kb | 2024-11-14 08:26:08 | 2024-11-14 08:26:15 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=3010;
const int inf=1e18;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
return x*f;
}
bool Mbe;
int n,a[maxn],ans;
int pre[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
inline int ksm(int a,int b=mod-2){
int ans=1;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
vector<int> id[maxn];
int dp[1<<15],f[1<<15];
int msk[maxn];
void work(){
n=read();
for(int i=1;i<=n;i++)a[i]=read();
for(int i=1;i<=n;i++){
int x=a[i];
for(int j=0;j<15;j++)if(x%pre[j]==0){
msk[i]|=1<<j;
while(x%pre[j]==0)x/=pre[j];
}
if(x==53*53)x=53;
id[x].pb(i);
}
dp[0]=1;
for(int i=1;i<=maxn-10;i++)if(id[i].size()){
for(int j:id[i]){
for(int s=(1<<15)-1;~s;s--){
(f[s|msk[j]]+=f[s]*(i==1?a[j]:a[j]/i*(i-1))+dp[s]*a[j])%=mod;
}
}
for(int s=0;s<(1<<15);s++)(dp[s]+=f[s])%=mod;
}
for(int s=0;s<(1<<15);s++)if(dp[s]){
int val=dp[s];
for(int i=0;i<n;i++)if(s&(1<<i)){
val=val*ksm(pre[i])%mod*(pre[i]-1)%mod;
}
// cout<<s<<" "<<dp[s]<<" "<<val<<"\n";
(ans+=val)%=mod;
}
printf("%lld\n",ans);
}
// \
444
bool Med;
int T;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
T=1;
while(T--)work();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4364kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4288kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 349ms
memory: 4384kb
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:
324909239
result:
wrong answer 1st lines differ - expected: '50965652', found: '324909239'