首页 > 其他分享 >[ARC158D] Equation

[ARC158D] Equation

时间:2024-01-18 16:59:53浏览次数:30  
标签:putchar int pow Equation ARC158D write include mod

题意

给定整数 \(n\) 以及模数 \(p\)。

你需要构造三元组 \((x, y, z)\) 满足:

  • \(1 \le x < y < z \le p - 1\)
  • \((x + y + z)(x ^ n + y ^ n + z ^ n)(x ^ {2n} + y ^ {2n} + z ^ {2n}) \bmod x ^ {3n} + y ^ {3n} + z ^ {3n} (mod p)\)

Sol

注意到你如果将左边的式子化简过后,一定是一堆系数乘一堆 \(x, y, z\) 的次方。

发现一个问题,如果我们设当前左边的值与右边的值的比为 \(t\)。

那么一定有一组答案为 \(frac{x}{y}, frac{y}{t}, frac{z}{t}\)。

\(p\) 为质数,所以只需要左右不为 \(0\) 就可以了。

yy一下感觉这个限制非常松,随便随几组就能对。

Code

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <array>
#include <random>
#define int long long
using namespace std;
#ifdef ONLINE_JUDGE

#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 23], *p1 = buf, *p2 = buf, ubuf[1 << 23], *u = ubuf;

#endif
int read() {
	int p = 0, flg = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') flg = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		p = p * 10 + c - '0';
		c = getchar();
	}
	return p * flg;
}
void write(int x) {
	if (x < 0) {
		x = -x;
		putchar('-');
	}
	if (x > 9) {
		write(x / 10);
	}
	putchar(x % 10 + '0');
}

int pow_(int x, int k, int p) {
	int ans = 1;
	while (k) {
		if (k & 1) ans = ans * x % p;
		x = x * x % p;
		k >>= 1;
	}
	return ans;
}
mt19937 rnd(147744151);

void solve() {
	int n = read(), mod = read();
	bool flg = 1;
	while (flg) {
		int x = rnd() % mod, y = rnd() % mod, z = rnd() % mod;
		int tp0 = ((x + y + z) * (pow_(x, n, mod) + pow_(y, n, mod) + pow_(z, n, mod)) % mod * (pow_(x, 2 * n, mod) + pow_(y, 2 * n, mod) + pow_(z, 2 * n, mod)) % mod) % mod, tp1 = (pow_(x, 3 * n, mod) + pow_(y, 3 * n, mod) + pow_(z, 3 * n, mod)) % mod;
		/* write(x), putchar(32); */
		/* write(y), putchar(32); */
		/* write(z), puts("@"); */
		if (x == y || y == z || x == z || !x || !y || !z || !tp0 || !tp1) continue;
		flg = 0;
		int t = tp1 * pow_(tp0, mod - 2, mod) % mod;
		x = x * t % mod, y = y * t % mod, z = z * t % mod;
		if (x > y) swap(x, y);
		if (y > z) swap(y, z);
		if (x > y) swap(x, y);
		write(x), putchar(32);
		write(y), putchar(32);
		write(z), puts("");
		flg = 0;
	}
}
signed main() {
	int T = read();
	while (T--) solve();
	return 0;
}

标签:putchar,int,pow,Equation,ARC158D,write,include,mod
From: https://www.cnblogs.com/cxqghzj/p/17972845

相关文章

  • 2. 会计恒等式 Accounting Equation
    投资人是企业所有者Owner借款给企业的人为债权人Credit'sEquity欠款为企业债务liabilitesAssets=Liabilites+Oner'sEquity资产=债务+所有者权益(AccountingEquation会计恒等式)这就是FinancialPosition财务状况,注意债务是正值它也是资产的一部分Assets......
  • 【RL】CH2-Bellman equation
    thediscountedreturn\[\begin{aligned}G_t&=R_{t+1}+\gammaR_{t+2}+\gamma^2R_{t+3}+\ldots\\&=R_{t+1}+\gamma\left(R_{t+2}+\gammaR_{t+3}+\ldots\right)\\&=R_{t+1}+\gammaG_{t+1}\end{aligned}\]state-valuefunction/the......
  • 题解 The Human Equation
    TheHumanEquation思维题。我们考虑每次\(a\)数组加一减一对于其前缀和\(sum\)的影响。可以发现,假设相邻两次加一和减一的位置分别为\(l\)和\(r\),那么\(sum\)在\([l,r)\)内会加一。先减后加也同理。所以,一次加减操作相当于将\(sum\)若干段连续序列加一或减一。......
  • Fourier Analysis and Nonlinear Partial Differential Equations 阅读笔记 (第一章)
    实分析基础Holder与卷积不等式首先从经典的Holder不等式入手.命题:经典情况下的Holder不等式设\((X,\mu)\)是测度空间,\((p,q,r)\in[1,\infty]^3\)满足\[\frac{1}{p}+\frac{1}{q}=\frac{1}{r}\]如果\((f,g)\inL^p(X,\mu)\timesL^q(X,\mu)\),则\(f\cdotg\inL^r(X,\m......
  • 山东第八届acm大赛F题quadratic equation,山东理工oj 3898
    题目地址:http://www.sdutacm.org/onlinejudge2/index.php/Home/Index/problemdetail/pid/3898.htmlquadraticequationTimeLimit: 2000MS MemoryLimit: 131072KBSubmit Statistic DiscussProblemDescriptionWithgivenintegers a,b,c,youareaskedto......
  • [ARC158D] Equation
    ProblemStatementYouaregivenapositiveinteger$n$,andaprimenumber$p$atleast$5$.Findatripleofintegers$(x,y,z)$thatsatisfiesallofthefollowingconditions.$1\leqx<y<z\leqp-1$.$(x+y+z)(x^n+y^n+z^n)(x^{2n}+y^{2n}+z^{......
  • [ARC144D] AND OR Equation
    ProblemStatementYouaregivenpositiveintegers$N$and$K$.Findthenumber,modulo$998244353$,ofintegersequences$\bigl(f(0),f(1),\ldots,f(2^N-1)\bigr)$thatsatisfyallofthefollowingconditions:$0\leqf(x)\leqK$forallnon-negative......
  • 15 Ray Tracing (Rendering Equation)
    关键点BRDF(BidirectionalReflectanceDistributionFunction)ReflectionEquationRenderingEquation1.BidirectionalReflectanceDistributionFunction(BRDF)1.1BRDF反射可以理解为光线打到物体表面被吸收,然后按照某些方向再辐射出去一部分。BRDF定义了从某一个......
  • Topcoder 10880 - Functional Equation
    首先分析一下这个鬼畜的函数,我们考虑\(f(x)+2C\)\(=f(2f(x)-x+1)+C\)\(=f(2f(2f(x)-x+1)-(2f(x)-x+1)+1)\)\(=f(2(f(x)+C)-2f(x)+x-1+1)\)\(=f(x+2C)\)也就是\(f(x)=f(x\bmod2C)+2C\lfloor\dfrac{x}{2C}\rfloor\)也就是,只要决定了\(f(x)\),\(f(x+2mC)\)也就被确定了。......
  • AtCoder Regular Contest 158 D - Equation
    题目链接原本看着式子直接晕了,觉得是高深的硬核数论,于是放弃(然后E也没想出来,sad)关键的思路在于,考虑构造由(a,b,c)->(ta,tb,tc)这样的求解方式。在看到这个做法后,会发现它很好地利用了题目齐次的性质;至于如何由齐次式想到这个做法,可能需要足够的天赋或者经验吧(悲)化简后得到\(At......