C++容斥原理—————表达式计数

这篇博客探讨了一道关于数列构造的问题,要求构造满足特定条件的数列a1, a2, ..., an,使得这些数的乘积等于另一组数b1, b2, ..., bn的乘积。博主通过分析指出,由于两组数的质因数分解相同,因此可以利用容斥原理来解决。博客内容包括问题描述、输入输出格式、样例、思路分析和C++代码实现,着重讲解如何利用容斥原理计算满足条件的数列方案数,并给出了递推组合数的方法。" 74531236,1010870,TensorFlow 中的 tf.split 和 tf.unstack 操作解析,"['深度学习', 'TensorFlow', '张量操作']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述:

给出n个数,b1,b2,b3……bn,构造n个数,a1,a2,……an(ai>1),使得a1*a2*a3……an=b1*b2……bn;

问一共有多少种数列a1,a2,……an满足上述条件。

输入:

包含多组输入数据

每组数据第一行有1个整数n(1<=n<=20)

每组数据第 二行有n个整数第i个数表示bi.(1<bi<=1000000)且b1*b2*…*bn <10^25)。

输出:

对于每组测试数据,输出有多少种数列满足情况,结果对1e9+7取余

输入样例:

2
3 4

输出样例:

4

提示:

思路分析:

想一想,如果它们的积相等则它们的质数唯一分解就相等。

毕竟是方案数,那么排列组合是一定的,那么我们先递推出组合数。

然后就是求解了。

我们可以这样想,指数就是特产的个数,而不同的底数就是特产,而n就是人数。

先考虑一种特产的情况:

可以使用容斥原理。设S表示全集,Pi表示至少有i个人没有分到特产的方案数。

D. Segments Covering time limit per test2 seconds memory limit per test256 megabytes    There is a linear strip divided into m cells, numbered from 1 to m from left to right. You are given n segments. Each segment is defined by four numbers: l , r , p and q — the segment covers cells from l to r inclusively and exists with probability pq (independently). Your task is to calculate the probability that each cell is covered by exactly one segment. AI 翻译    有一个线性长条被分成了 m 个格子,从左到右依次编号为 1 到 m 。 给定 n 个区间。每个区间由四个数定义:l 、r 、p 和 q —— 该区间覆盖从 l 到 r (包含 l 和 r )的格子,且该区间存在的概率为 pq (各区间相互独立)。 你的任务是计算每个格子恰好被一个区间覆盖的概率。    Input The first line contains two integers n and m (1≤n,m≤2⋅105 ). Then n lines follow. The i -th of them contains four integers li , ri , pi and qi (1≤li≤ri≤m ; 1≤pi<qi<998244353 ). AI 翻译    输入 第一行包含两个整数 n 和 m (1≤n,m≤2⋅105 )。 接下来有 n 行。其中第 i 行包含四个整数 li 、ri 、pi 和 qi (1≤li≤ri≤m ;1≤pi<qi<998244353 )。    Output Print a single integer — the probability that each cell is covered by exactly one segment, taken modulo 998244353 . Formally, the probability can be expressed as an irreducible fraction xy . You have to print the value of x⋅y−1mod998244353 , where y−1 is an integer such that y⋅y−1mod998244353=1 . AI 翻译    输出 输出一个整数 —— 每个单元格恰好被一个线段覆盖的概率,对 998244353 取模。 形式上,该概率可以表示为一个既约分数 xy 。你需要输出 x⋅y−1mod998244353 的值,其中 y−1 是一个整数,满足 y⋅y−1mod998244353=1 。 Examples InputCopy 3 3 1 2 1 3 3 3 1 2 1 3 2 3 OutputCopy 610038216 InputCopy 2 3 1 2 1 2 2 3 1 2 OutputCopy 0 InputCopy 8 5 1 3 1 2 1 5 1 6 1 4 4 5 5 5 1 7 4 5 1 2 4 5 2 5 3 3 2 7 1 2 1 3 OutputCopy 94391813    Note In the first example, the probability is equal to 518 . AI 翻译    注意 在第一个示例中,概率等于 518 。解决这个问题,并且给我一个c++代码
最新发布
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值