HDU 2662 Coin && HDU 1792 A New Change Problem (互質數最大不能生成數)

_TCgogogo_發表於2015-08-28


證明見here,寫的很不錯

2662 Coin

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

Total Submission(s): 903    Accepted Submission(s): 437

Problem Description
Moon has many coins, but only contains two value types which is 5 cents and 7 cents, Some day he find that he can get any value which greater than 23 cents using some of his coins. For instance, he can get 24 cents using two 5 cents coins and two 7 cents coins, he can get 25 cents using five 5 cents coins, he can get 26 cents using one 5 cents coins and three 7 cents coins and so on.

Now, give you many coins which just contains two value types just like Moon, and the two value types identified by two different prime number i and j. Can you caculate the integer n that any value greater than n can be created by some of the given coins.
 
Input
The first line contains an integer T, indicates the number of test cases.
For each test case, there are two different prime i and j separated by a single space.(2<=i<=1000000, 2<=j<=1000000)
 
Output
For each test case, output one line contains the number n adapt the problem description.

Sample Input
1 5 7
Sample Output
23
 
Source
HDU男生專場公開賽——趕在女生之前先過節(From WHU)

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=2662

題目大意:給兩個互質的數,求用無限個它們不能組成的最大的數

題目分析:當定理記吧,ans = n * m - n - m

#include <cstdio>
#define ll long long

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        ll a, b;
        scanf("%I64d %I64d", &a, &b);
        printf("%lld\n", a * b - a - b);
    }
}


1792 A New Change Problem

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 936    Accepted Submission(s): 515


Problem 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
 
題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1792

題目大意:給兩個互質的數,求用無限個它們不能組成的最大的數和不能組成的數的個數

題目分析:當定理記吧,不能組成的最大數n * m - n - m,不能組成的個數(n - 1) * (m - 1) / 2


#include <cstdio>

int main()
{
    int a, b;
    while(scanf("%d %d", &a, &b) != EOF)
        printf("%d %d\n", a * b - a - b, (a - 1) * (b - 1) / 2);
}

相關文章