跳到正文

题解

P10782 题解

Vitamin_B约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年7月14日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 1 分钟
题目
P10782

版本

  1. v1当前

思路

首先,如果有解,则 bb 一定可以为 aa 或 cc,这里就以 b=ab=a 为例,所以只要判有没有合法的 mm 就行。显然若有解,则 m=⌊ac⌋m=\lfloor\frac ac\rfloor 一定可行,所以只要看 ⌊a⌊ac⌋⌋=c\lfloor\frac a{\lfloor\frac ac\rfloor}\rfloor=c 是否成立即可。

代码

C++
# include <bits/stdc++.h>
# define I return
# define AK 0
# define IOI ;
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int t;
ll a, c;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> t;
	while (t --) {
		cin >> a >> c;
		cout << (a < c || a / (a / c) != c ? -1 : a) << '\n';
	}
	I AK IOI
}
原文