证明见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); }
版权声明:本文为博主原创文章,未经博主允许不得转载。