JZOJ1227 Coprime 题解

Posted World Of Wonder.

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JZOJ1227 Coprime 题解相关的知识,希望对你有一定的参考价值。


#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>

typedef long long ll;
const int N = 1e5 + 3;
const ll P = 131071;

int t, tot = 0, check[N], prime[N / 10];
ll n, m, jc[N], phi[N];

ll pow(ll x, ll p)
{
	ll ret = 1;
	while (p)
	{
		if (p & 1) ret = ret * x % P;
		x = x * x % P;
		p >>= 1;
	}
	return ret;
}

int main()
{
	freopen("coprime.in", "r", stdin);
	freopen("coprime.out", "w", stdout);

	jc[1] = 1; for (int i = 2; i <= N - 3; i++) jc[i] = jc[i - 1] * i % P;
	phi[1] = 1;
	for (int i = 2; i <= N - 3; i++)
	{
		phi[i] = phi[i - 1];
		if (!check[i]) phi[i] = phi[i] * (i - 1) % P * pow(i, P - 2) % P, prime[++tot] = i;
		for (int j = 1; j <= tot; j++)
		{
			if (i * prime[j] > N - 3) break;
			check[i * prime[j]] = 1;
			if (i % prime[j] == 0) break;
		}
	}
	scanf("%d", &t);
	while (t--)
	{
		scanf("%lld%lld", &n, &m);
		printf("%lld\\n", phi[m] * jc[n] % P);
	}

	fclose(stdin);
	fclose(stdout);
	return 0;
}

以上是关于JZOJ1227 Coprime 题解的主要内容,如果未能解决你的问题,请参考以下文章

题解JZOJ 提高A组 19.8.10 挖宝藏

hdu 6025 Coprime Sequence (前后缀GCD)

JZOJ3966 Sabotage 题解

洛谷 P1227 [JSOI2008]完美的对称

JZOJ 3468 OSU!题解

[JZOJ A组]球 题解