[关闭]
@xunuo 2017-02-27T11:46:30.000000Z 字数 870 阅读 835

HDU 1792 A New Change Problem(规律)


Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

数论


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。
有公式:A*x+B*y(x>=0,y>=0)
问利用这个公式最大不能表示的数和不能表示的数的个数。

解题思路:

个数为(A-1)*(B-1)/2;
最大不能表示的数为 A*B-A-B;
找规律=_=

完整代码:

  1. #include<stdio.h>
  2. int main()
  3. {
  4. int a,b;
  5. while(scanf("%d%d",&a,&b)!=EOF)
  6. {
  7. int maxnum=(a-1)*(b-1)/2;//不能支付的总人数
  8. int maxn=a*b-a-b;//不能支付的最大的数
  9. printf("%d %d\n",maxn,maxnum);
  10. }
  11. return 0;
  12. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注