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;
}
这两个博客也给出了证明: