Problem Statement

where the numerator of the fraction is the binomial coefficient: N!/(i!(N-i)!). There is one exception to this though: when K*2 is equal to N, the p-value is simply 1 (the above equation gives the wrong result).
This is all quite simple, when N and K are small, but what if they are rather large? Your task is to compute the p-value, given N and K, where 0<=K<=N<=1,000,000 and 0<N. You should return this value as a percentage with exactly one digit after the decimal point (don't forget the percent sign). You should use standard rounding when formatting your return. You need not worry about borderline cases as the constraints ensure that the percentage will not be within 1e-3 of XX.X5, where each X represents a digit.
Definition
- Class:
- LargeSignTest
- Method:
- pvalue
- Parameters:
- int, int
- Returns:
- String
- Method signature:
- String pvalue(int N, int K)
- (be sure your method is public)
Constraints
- N will be between 1 and 1,000,000, inclusive.
- K will be between 0 and N, inclusive.
- The percentage will not be within 1e-3 of XX.X5, where each X represents a digit.
Examples
5
4
Returns: "37.5%"
The p-value in this case is (choose(5,0)+choose(5,1))/2N-1 = (1+5)/16 = 6/16 = 3/8 = 37.5%
10
5
Returns: "100.0%"
1000000
400000
Returns: "0.0%"
20
5
Returns: "4.1%"
1000000
499000
Returns: "4.6%"
1000
499
Returns: "97.5%"
1000000
499900
Returns: "84.2%"
457751
229032
Returns: "64.5%"
954446
479806
Returns: "0.0%"
502911
249637
Returns: "0.0%"
162292
80431
Returns: "0.0%"
479035
238355
Returns: "0.1%"
292167
146597
Returns: "5.8%"
722324
364093
Returns: "0.0%"
300832
149379
Returns: "0.0%"
986163
495307
Returns: "0.0%"
212614
106655
Returns: "13.2%"
499735
250759
Returns: "1.2%"
465049
230910
Returns: "0.0%"
62707
31714
Returns: "0.4%"
426743
212838
Returns: "10.3%"
355025
177343
Returns: "57.1%"
512663
258013
Returns: "0.0%"
504064
252709
Returns: "5.7%"
732662
367636
Returns: "0.2%"
630450
316450
Returns: "0.2%"
513709
255519
Returns: "0.0%"
449366
226714
Returns: "0.0%"
627692
314911
Returns: "0.7%"
170104
84908
Returns: "48.7%"
570838
284285
Returns: "0.3%"
197878
98774
Returns: "46.0%"
506653
252639
Returns: "5.4%"
333151
165058
Returns: "0.0%"
79293
39398
Returns: "7.8%"
669425
335217
Returns: "21.8%"
605891
300970
Returns: "0.0%"
943172
469649
Returns: "0.0%"
865111
429194
Returns: "0.0%"
667554
334721
Returns: "2.1%"
882406
438049
Returns: "0.0%"
974458
491148
Returns: "0.0%"
129036
64181
Returns: "6.1%"
716422
359057
Returns: "4.6%"
560756
279169
Returns: "0.1%"
610338
307010
Returns: "0.0%"
972259
489086
Returns: "0.0%"
68449
34080
Returns: "27.1%"
750374
375915
Returns: "9.3%"
486053
241545
Returns: "0.0%"
684392
344465
Returns: "0.0%"
731670
368413
Returns: "0.0%"
768859
382409
Returns: "0.0%"
76081
37952
Returns: "52.3%"
892301
447204
Returns: "2.6%"
123559
61668
Returns: "52.8%"
815121
405574
Returns: "0.0%"
1000000
499999
Returns: "99.9%"
1000000
499996
Returns: "99.4%"
1000000
499000
Returns: "4.6%"
5
4
Returns: "37.5%"
1000000
499997
Returns: "99.6%"
1000000
499980
Returns: "96.9%"
1000000
499995
Returns: "99.3%"
2
0
Returns: "50.0%"
1000000
499900
Returns: "84.2%"
1000000
500001
Returns: "99.9%"
1000000
499599
Returns: "42.3%"
1
0
Returns: "100.0%"
1000
497
Returns: "87.4%"
1000000
200000
Returns: "0.0%"
1000000
499700
Returns: "54.9%"
1000
495
Returns: "77.6%"
202
100
Returns: "94.4%"
999999
499999
Returns: "100.0%"
1000000
498262
Returns: "0.1%"
81
40
Returns: "100.0%"
1001
459
Returns: "1.0%"