-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2979-MostExpensiveItemThatCanNotBeBought.go
More file actions
55 lines (45 loc) · 2.17 KB
/
2979-MostExpensiveItemThatCanNotBeBought.go
File metadata and controls
55 lines (45 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
// 2979. Most Expensive Item That Can Not Be Bought
// You are given two distinct prime numbers primeOne and primeTwo.
// Alice and Bob are visiting a market.
// The market has an infinite number of items, for any positive integer x there exists an item whose price is x.
// Alice wants to buy some items from the market to gift to Bob.
// She has an infinite number of coins in the denomination primeOne and primeTwo.
// She wants to know the most expensive item she can not buy to gift to Bob.
// Return the price of the most expensive item which Alice can not gift to Bob.
// Example 1:
// Input: primeOne = 2, primeTwo = 5
// Output: 3
// Explanation: The prices of items which cannot be bought are [1,3].
// It can be shown that all items with a price greater than 3 can be bought using a combination of coins of denominations 2 and 5.
// Example 2:
// Input: primeOne = 5, primeTwo = 7
// Output: 23
// Explanation: The prices of items which cannot be bought are [1,2,3,4,6,8,9,11,13,16,18,23].
// It can be shown that all items with a price greater than 23 can be bought.
// Constraints:
// 1 < primeOne, primeTwo < 10^4
// primeOne, primeTwo are prime numbers.
// primeOne * primeTwo < 10^5
import "fmt"
func mostExpensiveItem(primeOne int, primeTwo int) int {
return primeOne * primeTwo - primeOne - primeTwo
}
func main() {
// Example 1:
// Input: primeOne = 2, primeTwo = 5
// Output: 3
// Explanation: The prices of items which cannot be bought are [1,3].
// It can be shown that all items with a price greater than 3 can be bought using a combination of coins of denominations 2 and 5.
fmt.Println(mostExpensiveItem(2, 5)) // 3
// Example 2:
// Input: primeOne = 5, primeTwo = 7
// Output: 23
// Explanation: The prices of items which cannot be bought are [1,2,3,4,6,8,9,11,13,16,18,23].
// It can be shown that all items with a price greater than 23 can be bought.
fmt.Println(mostExpensiveItem(5, 7)) // 23
fmt.Println(mostExpensiveItem(2, 2)) // 0
fmt.Println(mostExpensiveItem(3967, 3967)) // 15729155
fmt.Println(mostExpensiveItem(2, 3967)) // 3965
fmt.Println(mostExpensiveItem(3967, 2)) // 3965
}