HDU 2662. Coin
原题链接
简单
作者:
史一帆
,
2021-08-31 16:05:56
,
所有人可见
,
阅读 210
/*
n + i = x1 * i + y1 * j n + j = x2 * i + y2 * j
n = (x1 - 1) * i + y1 * j n = x2 * i + (y2 - 1) * j
x1 = y2 = 0
n + i = y1 * j n + j = x2 * i n + i = n + j - j + i = (x2 + 1) * i - j
i 和 j 互质 x2 + 1 是 j 的倍数(令x2 + 1 == j)
n + i = i * j - j
n = i * j - i - j
*/
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
LL i, j;
int main() {
int T;
scanf("%d", &T);
while (T -- ) {
scanf("%lld%lld", &i, &j);
printf("%lld\n", i * j - i - j);
}
return 0;
}