Problem Statement
This problem statement contains superscripts that may not display properly outside the applet.
Kitayuta Mart is the largest supermarket in Shuseki Kingdom, offering a great variety of food and household products. The main products are fruits, especially apples. The store sells K kinds of apples, numbered from 1 to K. The price system is a little special: the original price of an apple of kind i (1 <= i <= K) is i yen (the currency of the kingdom). However, if a customer wants to buy more than one apple of kind i, the second apple will cost 2*i yen, the third apple will cost 22*i yen, and so on. In general, if a customer is buying n apples of kind i, the actual price of the j-th (1 <= j <= n) apple will be 2j-1*i yen. The store has a sufficient supply of each kind of apples.
Lun the dog loves apples. She wants to buy N apples at Kitayuta Mart. The kinds of apples does not matter to her, thus she will choose N apples so that the total price calculated using the above formula is minimized. You are given two
Definition
- Class:
- KitayutaMart
- Method:
- lastPrice
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int lastPrice(int N, int K)
- (be sure your method is public)
Notes
- It can be shown that the answer is unique.
Constraints
- N will be between 1 and 1,000,000,000, inclusive.
- K will be between 1 and 1,000,000,000, inclusive.
Examples
3
1
Returns: 4
The store sells only one kind of apples. Their original price is 1 yen. She will buy three of them, and the most expensive one will cost 22*1 = 4 yen.
3
2
Returns: 2
In this case, another kind of apples is also on sale. Instead of buying three of kind 1, she can buy two of kind 1 and one of kind 2. Their costs will be 1, 2, and 2 yen, so the most expensive apple in this case only costs 2 yen.
5
3
Returns: 4
This time, yet another kind of apples is available, and she needs five apples. There are two options: two of kind 1, two of kind 2, one of kind 3 three of kind 1, one of kind 2, one of kind 3 In either way, she will have to pay 4 yen for the most expensive apple.
1000000000
1
Returns: 570312504
In this extreme case, the price of an apple will reach 2999999999 yen.
987654321
876543210
Returns: 493827168
1
1
Returns: 1
2
1
Returns: 2
2
1000000000
Returns: 2
3
3
Returns: 2
4
2
Returns: 4
4
3
Returns: 3
4
4
Returns: 3
4
82373
Returns: 3
5
338841143
Returns: 4
10
469795038
Returns: 6
15
3920567
Returns: 8
15
385467295
Returns: 8
35
63
Returns: 19
36
63
Returns: 20
37
63
Returns: 20
38
63
Returns: 20
39
63
Returns: 21
40
63
Returns: 22
41
63
Returns: 22
64
96859931
Returns: 33
79
25659510
Returns: 41
81
7
Returns: 7168
90
63
Returns: 48
91
63
Returns: 48
92
63
Returns: 48
93
63
Returns: 48
94
63
Returns: 48
183
327
Returns: 94
322
373
Returns: 163
322
2636
Returns: 163
564
39689
Returns: 284
654
746989317
Returns: 329
848
46620
Returns: 427
873
4383
Returns: 440
3472
297492278
Returns: 1740
7327
4764
Returns: 3667
10000
1000000000
Returns: 5004
23623
84733
Returns: 11816
27076
346164451
Returns: 13542
32832
73232
Returns: 16418
44789
1682840
Returns: 22400
55574
49388
Returns: 27792
58933
670227306
Returns: 29472
64281
40524
Returns: 32145
91374
816110416
Returns: 45692
247051
954209858
Returns: 123530
750758
373855410
Returns: 375384
2393627
1674
Returns: 999026502
2906682
616531489
Returns: 1453346
6114416
133017382
Returns: 3057215
6240730
452262198
Returns: 3120372
7368841
959584
Returns: 51563072
7661137
717023
Returns: 309232640
8647499
95668
Returns: 263685741
10198783
37
Returns: 527266470
22057479
7966
Returns: 26570049
66442405
11860
Returns: 326332281
72884870
611802957
Returns: 36442440
82364646
38
Returns: 991486540
104086214
801456050
Returns: 52043114
148371534
7587706
Returns: 711113665
151403858
302852177
Returns: 75701936
178275374
10
Returns: 459365159
211961529
708865200
Returns: 105980770
291388018
836522883
Returns: 145694016
298984849
807370501
Returns: 149492432
300735188
16
Returns: 211686802
303154838
41
Returns: 258309882
320861287
949502693
Returns: 160430652
360621153
177
Returns: 163701177
368712057
110
Returns: 3535305
370061683
20479689
Returns: 695831235
406486383
712020460
Returns: 203243200
408297065
81205484
Returns: 667801152
410442627
99863879
Returns: 443404032
423728044
680589140
Returns: 211864029
431793980
1900877
Returns: 69622281
439165413
31273839
Returns: 552208989
484800872
817752860
Returns: 242400445
517082547
194971110
Returns: 322111452
545040495
349226636
Returns: 272520255
558427013
2
Returns: 668111021
600229478
14507012
Returns: 528641740
618973530
925332874
Returns: 309486772
623452241
58579054
Returns: 637636440
633916535
2489209
Returns: 327615069
675068807
224155941
Returns: 453513872
692701178
50
Returns: 474348601
697361880
4
Returns: 325753967
712384807
352584036
Returns: 359800788
721501126
551
Returns: 851184460
722210475
704387675
Returns: 361105244
739014523
184176866
Returns: 745935752
759893834
5208
Returns: 461628898
784916702
230290042
Returns: 648673276
811409044
41
Returns: 156042987
818575853
10
Returns: 22982012
820283378
21438417
Returns: 510681560
821005795
306077643
Returns: 514928168
835228347
246071042
Returns: 686172552
845990695
772528466
Returns: 422995356
851433670
750005226
Returns: 425716844
864042774
207433349
Returns: 966970968
917937478
240749374
Returns: 872877488
429865193
119075969
Returns: 383426548
999999995
63
Returns: 79765447
999999996
63
Returns: 267558083
999999997
63
Returns: 267558083
999999998
63
Returns: 267558083
999999999
63
Returns: 455350719
1000000000
63
Returns: 643143355
1000000000
268435454
Returns: 926258212
1000000000
268435455
Returns: 926258208
1000000000
268435456
Returns: 926258208
1000000000
500000005
Returns: 500000010
1000000000
500000006
Returns: 500000008
1000000000
900000000
Returns: 500000008
1000000000
999999997
Returns: 500000008
1000000000
999999998
Returns: 500000008
1000000000
999999999
Returns: 500000008
1000000000
22222
Returns: 421001024
1000000000
1000000000
Returns: 500000008
31321321
24234
Returns: 552632306
1000000000
8374
Returns: 510978640
10000000
1000000
Returns: 256002048
7
3
Returns: 6
999999000
100000
Returns: 999103491
1
33
Returns: 1