【HDU - 1792】A New Change Problem(推公式、互质数的最大不能表示数)

本文探讨了给定两个互质数a和b时,如何求解由它们组成但无法表示的最大数及其数量。通过分析得出,最大不可表示数为(a-1)*b-a,不可表示数的总个数为(a-1)*(b-1)/2。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can assume that there are enough coins for both kinds.Please calculate the maximal value that you cannot pay and the total number that you cannot pay.

Input

The input will consist of a series of pairs of integers A and B, separated by a space, one pair of integers per line. 

Output

For each pair of input integers A and B you should output the the maximal value that you cannot pay and the total number that you cannot pay, and with one line of output for each line in input.

Sample Input

2 3
3 4

Sample Output

1 1
5 3

题意:

给定两个互质的数 a ,b ,求不限数量个 a 和 b 组成的数中最大不能表示的数,和不能表示的数的个数。 

思路:(给出证明过程的博客

看了别人的博客,才知道能推出公式。最大不能表示的数是 (a-1)*b-a,个数是 (a-1) * (b-1) / 2。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;

int main()
{
	ll a,b;
	while(~scanf("%lld%lld",&a,&b))
	{
		printf("%lld %lld\n",(a-1)*b-a,(a-1)*(b-1)/2);
	}
	return 0;
}

这两个博客也给出了证明:

博客1博客2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值