跳到正文

题解

题解:P13836 微观戏剧(Constructive ver.)

Charged_Charge约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
P13836

版本

  1. v1当前

洛谷 P13836

解题思路:

首先,我们要先做出 P11275 这道题。根据前面题目的结论:z=0z=0 时,令 x0=y0x_0 = y_0 即可;当 z=1z=1,没有任何的两个数最小公倍数为 11,此时无解。由于题目要求 x0,y0≤1018x_0,y_0\le 10^{18},所以当 zz 小于等于 101810^{18},让 x0=1x_0=1,y0=zy_0 = z 即可;而如果 z>1018z> 10^{18},可以考虑 x0+y0=zx_0+y_0=z,而这时还要判断奇数与偶数。通过画图发现,奇数情况时,x0=⌊z2⌋x_0 = \left\lfloor\dfrac{z}{2}\right\rfloor,y0=⌊z2⌋+1y_0 = \left\lfloor\dfrac{z}{2}\right\rfloor+1;偶数情况时,x0=z2−1x_0 = \dfrac{z}{2}-1,y0=z2+1y_0 = \dfrac{z}{2}+1。

AC 代码:

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int q;
signed main() {
	cin >> q;

	while (q--) {
		int x;
		cin >> x;

		if (x == 0) {
			cout << "1 1" << endl;
		} else if (x == 1) {
			cout << "-1 -1" << endl;
		} else if (x < 1e18) {
			cout << 1 << " " << x << endl;
		} else {
			if (x % 2 == 1) {
				cout << x / 2 << " " << x / 2 + 1 << endl;
			} else {
				cout << x / 2 - 1 << " " << x / 2 + 1 << endl;
			}
		}
	}

	return 0;
}
原文