HDU 1792 A New Change Problem

保持熱愛,不忘初心發表於2019-02-08

題目描述
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.
譯文:已知兩種硬幣A和B,滿足GCD(A,B)=1。這裡你可以假設兩種硬幣都有足夠的硬幣。請計算您無法支付的最大值和您無法支付的總數
輸入
The input will consist of a series of pairs of integers A and B, separated by a space, one pair of integers per line.
譯文:輸入將由一系列的整數對a和B組成,由一個空格分隔,每行一對整數。
輸出
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.
譯文:對於每對輸入整數A和B,應該輸出不能支付的最大值和不能支付的總數,並且輸入中的每一行都有一行輸出。)
樣例:
輸入:
2 3
3 4
輸出:
1 1
5 3

題解:(找規律)在這裡插入圖片描述
程式碼:

#include<stdio.h>
int main()
{
    int A,B;
    while(scanf("%d%d",&A,&B)!=EOF)
    {
        int m=A*B-A-B;
        int n=(A-1)*(B-1)/2;
        printf("%d %d\n",m,n);
    }
    return 0;
}

相關文章