2017CCPC杭州部分题解

Problem B. Master of Phi:

2017CCPC杭州部分题解_第1张图片

题意:给m对数p, q,令n = \prod_{i}^{m}p_{i}\cdot q_{i},求\sum _{d|n}\varphi (d)\cdot \frac{n}{d},其中\varphi (d) = d\cdot \prod_{p|d}(1 - \frac{1}{p}).

思路:公式化简。

          

2017CCPC杭州部分题解_第2张图片

 AC代码:

/*---------------------------------
 *File name: 2017杭州B.cpp
 *Team: 这题太简单啦
 *Author: Snpilola
 *Creation date: 2019-10-08 15:37
 *-------------------------------*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define fi first
#define se second
#define pb push_back
#define LL long long
#define mkp make_pair
#define PLL pair
#define lowbit(x) x & (-x)
#define PII pair
#define Pque priority_queue 
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int EPS = 1e-6;

LL fpow(LL x, LL y){
	LL ans = 1;
	while(y){
		if(y & 1) ans = ans * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}

int main(){
	int t; scanf("%d", &t);
	while(t--){
		int m;
		LL p, q;
		LL ans = 1;
		scanf("%d", &m);
		for(int i = 1; i <= m; i++){
			scanf("%lld %lld", &p, &q);
			ans = ans * fpow(p, q - 1) % mod * ((p + (p - 1) * q % mod) % mod) % mod;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

 

你可能感兴趣的:(题解)