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

本文探讨了给定两种互质面额硬币时无法构成的最大数值及其数量的问题,并提供了两种算法实现,一种用于找出不可构成的最大数值,另一种同时计算该最大数值及不可构成的所有数值的数量。


证明见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);
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值