QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742744#9619. 乘积,欧拉函数,求和ATM12345#AC ✓1863ms5268kbC++172.3kb2024-11-13 17:13:212024-11-13 17:13:26

Judging History

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

  • [2024-11-13 17:13:26]
  • 评测
  • 测评结果:AC
  • 用时:1863ms
  • 内存:5268kb
  • [2024-11-13 17:13:21]
  • 提交

answer

#include <bits/stdc++.h>
#define ll int
#define LL long long
#define ls p<<1
#define rs p<<1|1
#define Ma 3005
#define mod 998244353
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 16
#define pb push_back
#define ld long double
#define all(x) x.begin(),x.end()
#define inf 1e18

using namespace std;
ll n,m,k;
ll a[Ma];
ll p[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};//16
//53*59

struct node{
	vector <ll> v;
	ll col,x;
	bool operator <(const node &A)const{
		return v.back()<A.v.back();
	}
	bool operator !=(const node &A)const{
		return v.back()!=A.v.back();
	}
}T[Ma];


ll po(ll p,ll x=mod-2)
{
	ll sum=1;
	while (x)
	{
		if (x&1) sum=(LL)sum*p%mod;
		p=(LL)p*p%mod;
		x>>=1;
	}
	return sum;
}

ll pw[Ma];

void go(ll x,ll id)
{
	T[id].x=x;
	vector <ll> v;
	ll col=0;
	if (x==1)
	{
		v.pb(1);
		T[id].v=v;
		return;
	}
	for (ll i=0;i<N;i++)
	{
		while (x%p[i]==0)
			x/=p[i],v.pb(p[i]),col|=(1<<i);
	}
	if (x!=1)
		v.pb(x);
	T[id].v=v,T[id].col=col;
	return;
}

ll dp[1<<N][2],ne[1<<N][2];


void add(ll &x,ll y)
{
	x=(x+y)%mod;
}

void sol()
{
	for (ll i=1;i<Ma;i++)
		pw[i]=po(i);
	cin>>n;
	for (ll i=1;i<=n;i++)
	{
		ll x;
		cin>>x;
		go(x,i);		
	}
	sort(T+1,T+n+1);
	dp[0][0]=1;
	for (ll i=1;i<=n;i++)
	{
		if (i>1&&T[i]!=T[i-1])
		{
			for (ll j=0;j<(1<<N);j++)
				add(dp[j][0],dp[j][1]),dp[j][1]=0;
		}
		for (ll j=0;j<(1<<N);j++)
			ne[j][0]=dp[j][0],ne[j][1]=dp[j][1];
		for (ll j=0;j<(1<<N);j++)
		{
			if (T[i].v.back()==1)
			{
				add(ne[j][0],dp[j][0]),add(ne[j][1],dp[j][1]);
				continue;
			}
			ll res0=T[i].x;
			
			ll np=(j|T[i].col);
			for (ll o=0;o<N;o++)
			{
				if ((np-j)>>o&1)
					res0=(LL)res0*(p[o]-1)%mod*pw[p[o]]%mod;	
			}
			
			ll res1=res0;
			if (T[i].v.back()>p[N-1])
				res1=(LL)res1*(T[i].v.back()-1)%mod*pw[T[i].v.back()]%mod;
			add(ne[np][1],((LL)dp[j][0]*res1+(LL)dp[j][1]*res0)%mod);
		}
		swap(ne,dp);
	}
	ll res=0;
	for (ll i=0;i<(1<<N);i++)
		add(res,(dp[i][0]+dp[i][1])%mod);
	printf("%d\n",res);
	return;
}

int main()
{
	IOS
	ll tt=1;
	//cin>>tt;
	while (tt--)
		sol();
	return 0;
}


/*
3
1 2 3

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 4860kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 6ms
memory: 4936kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: 0
Accepted
time: 626ms
memory: 5164kb

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:

50965652

result:

ok single line: '50965652'

Test #4:

score: 0
Accepted
time: 636ms
memory: 5008kb

input:

2000
1 1 1 1 1 1 1 1 353 1 1 1 557 1 1 1 1 1 1 1 1 1 1 1 1423 1 1 1327 1 1 1 907 1 1 1 1 1 2971 1 1 1 2531 1 1 1 1 1 1 1 1 1 2099 1 1 1 1 1 1 1 1 1 1 1 1 1 1 199 2999 1 727 1 1 1 1 1 1 1 71 1 1 1 1 1 1 2503 1 176 1 1 1 1 1 1 1361 1013 1 1 1 1 1 1 1 2699 1 1 1 1 1 1 1 1 1 2897 1 1 1 1 1637 1 1 1367 1...

output:

420709530

result:

ok single line: '420709530'

Test #5:

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

input:

30
37 14 35 33 38 42 46 3 26 7 16 1 35 38 48 3 43 49 18 3 29 1 43 43 20 6 39 20 14 38

output:

262613273

result:

ok single line: '262613273'

Test #6:

score: 0
Accepted
time: 29ms
memory: 5128kb

input:

30
39 31 49 2 4 28 30 12 13 34 7 28 17 37 38 18 41 33 29 36 18 7 3 14 30 42 35 14 18 35

output:

234142118

result:

ok single line: '234142118'

Test #7:

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

input:

200
53 37 234 248 66 30 64 181 38 130 250 27 199 226 43 185 207 241 38 296 68 18 145 20 64 127 57 30 168 267 221 116 115 192 17 26 5 63 3 127 52 48 229 58 69 111 20 244 234 35 48 217 179 189 89 60 285 106 43 104 36 28 62 281 104 38 281 264 140 275 105 20 203 271 222 262 123 10 82 263 118 254 229 222...

output:

617035263

result:

ok single line: '617035263'

Test #8:

score: 0
Accepted
time: 181ms
memory: 5136kb

input:

200
119 128 228 63 117 123 211 147 116 286 29 252 5 216 146 224 220 103 78 269 12 53 245 121 123 139 210 132 122 207 9 46 265 128 167 171 207 120 99 135 27 9 111 192 228 295 33 156 151 59 240 90 2 254 36 58 168 228 220 57 154 268 20 244 272 71 207 290 132 231 115 277 97 32 28 184 172 24 198 218 79 8...

output:

942938793

result:

ok single line: '942938793'

Test #9:

score: 0
Accepted
time: 1851ms
memory: 5268kb

input:

2000
1516 1151 2408 2818 654 542 743 2216 777 1267 279 2373 605 367 2837 1608 2611 2315 883 2309 1185 832 1850 1696 1774 269 2448 2397 163 2223 715 1845 2805 467 519 585 323 517 1792 2206 2125 2984 1019 1777 193 972 1804 2408 2954 1155 1217 1959 1647 553 2716 2591 982 2776 1687 1504 2753 333 1803 23...

output:

462102486

result:

ok single line: '462102486'

Test #10:

score: 0
Accepted
time: 1863ms
memory: 4920kb

input:

2000
499 440 979 1745 645 2425 723 1469 1411 1974 1893 1648 1439 128 746 895 678 198 1517 518 1412 1216 2409 923 2055 2178 1901 158 969 1897 1484 1987 399 2711 2538 1580 1512 1357 2693 106 1852 621 1466 1555 873 758 1296 1609 1309 2334 1039 234 1986 2303 391 1478 578 1705 1487 1876 444 1015 150 2604...

output:

167633619

result:

ok single line: '167633619'