2022-06-02每日刷题打卡

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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值