@xunuo
2017-02-27T19:46:30.000000Z
字数 870
阅读 930
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
数论
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.
The input will consist of a series of pairs of integers A and B, separated by a space, one pair of integers per line.
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.
2 3
3 4
1 1
5 3
题意:
给你两个互质的数A,B。
有公式:A*x+B*y(x>=0,y>=0)
问利用这个公式最大不能表示的数和不能表示的数的个数。
解题思路:
个数为(A-1)*(B-1)/2;
最大不能表示的数为 A*B-A-B;
找规律=_=
完整代码:
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
int maxnum=(a-1)*(b-1)/2;//不能支付的总人数
int maxn=a*b-a-b;//不能支付的最大的数
printf("%d %d\n",maxn,maxnum);
}
return 0;
}