2022-06-02每日刷题打卡
代码源——每日一题
一个大整数 - 题目 - Daimayuan Online Judge
题目描述
现在有一个非常大的整数 x,可以将其表示为x=∏ni=1pcii,pi代表一个质数,请问有多少对 x的因子是互质的。
输入描述
第一行输入一个整数 T(1≤T≤102),代表有 T组测试样例。 对于每一个测试样例第一行的输入一个整数n(1≤n≤104)。 接下来 n行,每行两个整数分别代表 pi和 ci,其中 1≤pi,ci≤109,保证pi是一个质数,且互不相同。
输出描述
输出 T行,每行一个整数代表答案,答案可能会很大,请对 10^9+7取模。
样例输入
1
2
2 2
3 1
样例输出
15
样例解释
x = 12,因子为1,2,3,4,6,12
互质的因子对为
(1, 1), (1, 2), (1, 3), (1, 4), (1, 6)
(1, 12), (2, 1), (2, 3), (3, 1), (3, 2)
(3, 4), (4, 1), (4, 3), (6, 1), (12, 1)共15对
问题解析
对于一个互质的因子对,因为(a,b)和(b,a)我们是不一样的,那么对于一个因子,我们可以把它放在左边,也可以把它放在右边,也可以不选它,那么对于一个数来说它共有(2*ci+1)个选择。那么所有的结果就是(2 *ci+1)从i=1乘到i=n为止;
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>
#include <sstream>
#define endl '\n'
#define int ll
typedef long long ll;
typedef pair<ll, ll>PII;
typedef unsigned long long ull;
const int MOD = 1e9 + 7;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--)
{
ull n, res = 1, x, c;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x >> c;
res = (res * (2 * c + 1)) % MOD;
}
cout << res << endl;
}
return 0;
}