Input file: standard
Input Output file: standard
Output Time limit: 1 second
Memory limit: 512 megabytes
Problem Description
Cuber QQ likes QQ Speed, he always plays the game throughout all night, until early morning.
On a dark and gusty night, as usual, Cuber QQ was playing the 48-player knockout round of QQ Speed, and it was his turn to “ban the map”. He suddenly had an idea for the programming contest.
In each contest round, there are n players. The gaming system will give all players x maps, and each player can ban a map. After that, the gaming system will evenly, but not necessarily randomly, divide the players into m groups (m divides n). Every player in the same group must race on the same map, and different groups can either race on the same map or not. If one of the players in the group have banned a map, this map cannot be used by this group any more. Now, Cuber QQ wants to know the minimal number of maps the gaming system needs to provide to the players, and these maps can ensure having at least one grouping scheme in any case.
Input
The first line contains a single integer T (1 ≤ T ≤ 105 ) — the number of test cases. Each of the next T lines contains two integers n and m (1 ≤ n, m ≤ 109 , m | n).
Output
For each test case, output one line containing one integer which is the answer.
Example
Standard IputStandard Oputput248 84 233Solution
😀 算法标签:数学/思维- 如果所有人在同一组里,由于每个人都可能会禁掉不同的地图,因此我们应该有 n + 1 n + 1 n+1张地图;
- 如果每个人单独一组,则需要2张图;
- 其余情况下,只需要3张地图即可满足题意。
#include
#define itn int
#define ll long long
#define rnt register int
#define ull unsigned long long
#define IOF ios_base::sync_with_stdio(false)
#pragma GCC optimize("no-stack-protector")
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
signed main(){
IOF;
int T = 0; cin >> T;
while (T--){
int n, m; cin >> n >> m;
if (n == m) cout
关注
打赏
- 回坑记之或许是退役赛季?
- [LCT刷题] P1501 [国家集训队]Tree II
- [LCT刷题] P2147 洞穴勘测
- 2022-2023 ICPC Brazil Subregional Programming Contest VP记录
- [线段树套单调栈] 2019-2020 ICPC Asia Hong Kong Regional Contest H.[Hold the Line]
- The 2021 ICPC Asia Nanjing Regional Contest E.Paimon Segment Tree 区间合并线段树/维护矩阵乘法
- CF580E - Kefa and Watch 线段树维护哈希
- HDU5869 Different GCD Subarray Query 离线查询/区间贡献
- 27.CF1004F Sonya and Bitwise OR 区间合并线段树
- 26.CF1000F One Occurrence