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.
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)
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
Input
Output
Sample Input
Sample Output
題目連結: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
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.
The input will consist of a series of pairs of integers A and B, separated by a space, one pair of integers per line.
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.
2 3
3 4
1 1
5 3
題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1792
題目大意:給兩個互質的數,求用無限個它們不能組成的最大的數和不能組成的數的個數
題目分析:當定理記吧,不能組成的最大數n * m - n - m,不能組成的個數(n - 1) * (m - 1) / 2
題目大意:給兩個互質的數,求用無限個它們不能組成的最大的數和不能組成的數的個數
題目分析:當定理記吧,不能組成的最大數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);
}
相關文章
- HDU 1792-A New Change Problem(互質數的最大不能表示數)
- 【HDU - 1792】A New Change Problem(推公式、互質數的最大不能表示數)公式
- hdu 1792 A New Change Problem(數論)
- 類最大hdu 1792 A New Change Problem
- HDU 1792 A New Change Problem
- HDU 1792 - A New Change Problem(規律,最大不能組合數及其個數)
- Hdu 1792 A New Change Problem 結論
- hdu 1792 A New Change Problem 剩餘系
- 數學規律題,數論知識:hdu1792
- HDU1792(公式)公式
- HDU5293 : Tree chain problemAI
- HDU 4135 Co-prime(容斥原理+分解質因數)
- hdu 2097 Java Sky數Java
- hdu 4292 網路最大流
- hdu 2072 Java 單詞數(超級坑) HDU 2072Java
- HDU 4944 FSF’s game(計數遊戲)GAM遊戲
- HDU 2254 奧運(數論+矩陣)矩陣
- HDU 4497GCD and LCM(素數分解)GC
- HDU 1299 Diophantus of Alexandria (公式變形 分解質因數)公式
- HDU 2256Problem of Precision(矩陣快速冪)矩陣
- hdu5435 數位dp(大數的處理)
- 【KMP求字串匹配次數】 hdu 1686KMP字串匹配
- HDU 4497 GCD and LCM(拆素數+組合)GC
- HDU 2582 f(n) (組合數的gcd)GC
- HDU5425Rikka with Tree II(數學期望)
- hdu1297大數遞迴遞迴
- 求最大質因數
- HDU 4291 A Short problem(矩陣快速冪+迴圈節)矩陣
- HDU 2732 Leapin' Lizards(拆點+最大流)API
- LeetCode-Coin ChangeLeetCode
- HDU 6034 Balala Power!(大數進位制)
- HDU44979 GCD and LCM (素因子分解+計數)GC
- HDU4342 History repeat itself數學規律題
- HDU 4911 Inversion(歸併排序求逆序數)排序
- X問題(中國剩餘定理+不互質版應用)hdu1573
- iOS生成最大最小數之間隨機數iOS隨機
- HDU 1060 Leftmost Digit(數論,c++)GitC++
- hdu 3117矩陣+斐波那契數列矩陣