97pts WA#15
  • 板块P9836 种树
  • 楼主Lawsless
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/11/13 18:57
  • 上次更新2023/11/18 17:00:31
查看原帖
97pts WA#15
468238
Lawsless楼主2023/11/13 18:57
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int P = 998244353;

struct node{
	priority_queue < int , vector < int > , greater < int > > q;
};
node a[11005];

int v(int p,int &n)
{
	int cnt = 0;
	while (n % p == 0) n /= p,cnt++;
	return cnt;
}

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 * 10 + ch - '0',ch = getchar();
    return x * f;
}

void write(long long x)
{
    if(x < 0)
        putchar('-'),x = -x;
    if(x > 9)
        write(x / 10);
    putchar(x % 10 +'0');
    return;
}

signed main()
{
	int n,w,x;
	n = read(),w = read();
	for (int i = 1;i <= n;i++)
	{
		x = read();
		int t = x;
		for (int j = 2;j <= x && t != 1;j++)
		{
			int po = v(j,t);
			a[j].q.push(po + 1);
		}
	}
	int k = w;
	for (int i = 2;i <= k && w != 1;i++)
	{
		int c = v(i,w);
		for (int j = 1;j <= c;j++)
		{
			if (a[i].q.empty()) continue;
			int t = a[i].q.top();
			a[i].q.pop();
			t++;
			a[i].q.push(t);
		}
	}
	long long ans = 1;
	for (int i = 2;i <= 10000;i++)
		while (!a[i].q.empty())
		{
			ans = (ans * a[i].q.top()) % P;
			a[i].q.pop();
		}
	write(ans);
	return 0;
}

2023/11/13 18:57
加载中...