QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740827#9619. 乘积,欧拉函数,求和jdyt11TL 264ms4260kbC++203.3kb2024-11-13 11:44:062024-11-13 11:44:07

Judging History

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

  • [2024-11-13 11:44:07]
  • 评测
  • 测评结果:TL
  • 用时:264ms
  • 内存:4260kb
  • [2024-11-13 11:44:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define inf 0x3f3f3f3f
#define ull unsigned long long
#define pll pair<ll,ll>
#define ls d*2
#define rs d*2+1
#define mid (l+r)/2
#define lowbit(x) (x&(-x))
//#define endl "\n"
#define all(x) x.begin(),x.end()
#define int long long
//mt19937 seed;
//uniform_int_distribution<int>num(0,2e9);
const int N=2e5+10;
const int M=33;

int mod=998244353;
int dp[1<<17];
int prime[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,1};
int kp(int x,int y){
	int re=1;
	while(y){
		if(y&1)re=re*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return re;
}
void solve() {
	int n;
    map<int, vector<pair<int, int>>> mp;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        int nd = 0, sum = 1;
        for (int i = 0; i < 16; i++) {
            while (x % prime[i] == 0) {
                x /= prime[i];
                sum = (sum * prime[i]) % mod;
                nd |= (1 << i);
            }
        }
        mp[x].push_back({nd, sum});
    }
    vector<int> dp(1 << 17);
    dp[0] = 1;
    for (auto [x, vec] : mp) {
        prime[16] = x;
        for (auto [nd, sum] : vec) {
            if (x != 1)
                nd |= 1 << 16;
            for (int i = (1 << 17) - 1; i >= 0; i--) {
                int nsum = sum, nnd = nd | i;
                if ((i & (1 << 16)) != 0)
                    nsum = (nsum * x) % mod;
                else
                    nsum = (nsum * max(x - 1, 1ll)) % mod;
                dp[nnd] = (dp[nnd] + dp[i] * nsum % mod) % mod;
            }
        }
        for (int i = (1 << 16); i < (1 << 17); i++) {
            int ni = i ^ (1 << 16);
            dp[ni] = (dp[ni] + dp[i]) % mod;
            dp[i] = 0;
        }
    }
    int sum = 0;
    for (int i = 0; i < (1 << 17); i++) {
        for (int j = 0; j < 16; j++) {
            if ((i & (1 << j)) != 0) {
                dp[i] = (dp[i] * kp(prime[j], mod - 2)) % mod;
                dp[i] = (dp[i] * max(prime[j] - 1, 1ll)) % mod;
            }
        }
        sum = (sum + dp[i]) % mod;
    }
    cout << sum << '\n';
    return;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int _=1;//cin>>_;
    while(_--){
//        int n;
//        cin>>n;
//        map<int,vector<pair<int,int>>>mp;
//        for(int i=0;i<n;i++){
//        	int x;
//        	cin>>x;
//        	int num=0,sum=1;
//        	for(int j=0;j<16;j++){
//        		while(x%pri[j]==0)num|=(1<<j),sum*=pri[j],x/=pri[j];
//			}
//			mp[x].push_back({num,sum});
//		}
//		dp[0]=1;
//		for(auto [x,vec]:mp){
//			pri[16]=x;
//			for(auto [num,sum]:vec){
//				if(x!=1)num|=(1<<16);
//				for(int i=(1<<17)-1;i>=0;i--){
//					if(i>>16&1)dp[i|num]=(dp[i|num]+dp[i]*sum%mod*x%mod)%mod;
//					else dp[i|num]=(dp[i|num]+dp[i]*sum%mod*max(x-1,1ll)%mod)%mod;
//				}
//			}
//			for(int i=(1<<16);i<(1<<17);i++){
//				dp[i-(1<<16)]=(dp[i-(1<<16)]+dp[i])%mod;
//				dp[i]=0;
//			}
//		}
//		int ans=0;
//		for(int i=0;i<(1<<17);i++){
//			for(int j=0;j<16;j++){
//				if(i>>j&1){
//					dp[i]=dp[i]*(pri[j]-1)%mod;
//					dp[i]=dp[i]*qp(pri[j],mod-2)%mod;
//				}
//			}
//			ans=(ans+dp[i])%mod;
//		}
//		cout<<ans<<'\n';
solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 264ms
memory: 4260kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 263ms
memory: 4068kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Time Limit Exceeded

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:


result: