Description
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,它们满足GCD(A,B)= 1。在这里,您可以假定这两种硬币都有足够的硬币。请计算您不能支付的最大值和无法支付的总数。
思路
我还是找不到规律,只能打表找。
AC代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b;
int n1,n2;
int main()
{
while(cin>>a>>b&&a&&b)
{
n1=a*b-a-b;
n2=(a-1)*(b-1)/2;
cout<<n1<<" "<<n2<<endl;
}
return 0;
}

本文探讨了给定两种硬币A和B(满足GCD(A,B)=1)的情况下,如何计算无法用这两种硬币组合支付的最大值和无法支付的总数。文章提供了一个简洁的C++代码示例,用于解决这一数学问题。
11万+

被折叠的 条评论
为什么被折叠?



