题意
给定整数 \(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