「NOIP2017」小凯的疑惑
题目描述
小凯手中有两种面值的金币,两种面值均为正整数且彼此互素。每种金币小凯都有无数个。在不找零的情况下,仅凭这两种金币,有些物品他是无法准确支付的。现在小凯想知道在无法准确支付的物品中,最贵的价值是多少金币?注意:输入数据保证存在小凯无法准确支付的商品。
题目链接
NOIP2017 小凯的疑惑
题解
不妨设
假设答案为
若
即
显然当
因此当
显然当
因此
代码
#include <cstdio>
typedef long long ll;
int main(int argc, char *argv[]) {
freopen("math.in", "r", stdin);
freopen("math.out", "w", stdout);
int a, b;
scanf("%d %d", &a, &b);
printf("%lld\n", a * b - a - b);
fclose(stdin);
fclose(stdout);
return 0;
}