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

bfcx發表於2019-04-27

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

相關文章