/*
* n 種のガチャポンなり食玩なりを
* m 回でコンプリートする確率
*
*/
#include
#include
#include
#include
static int verbose;
/*
* nCr = n! / r! / (n - r)!
*/
static long long
combination(int n, int r)
{
int i;
long long x = 1;
long long y = 1;
for (i = 0; i < r; i++) {
x *= n--;
y *= (i + 1);
}
return x / y;
}/* combination */
static double
ipow(double x, int n)
{
int i;
double y = 1.0;
for (i = 0; i < n; i++) {
y *= x;
}
return y;
}/* ipow */
static double
nn_p(int ntypes, int times)
{
int i;
double sign = (ntypes % 2 == 0) ? -1 : 1;
double sigma = 0;
for (i = 0; i < ntypes; i++) {
sigma += sign * combination(ntypes - 1, i) * ipow((double)(i + 1) / ntypes, times - 1);
sign = sign < 0 ? 1 : -1;
}
return sigma;
}/* nn_p */
int
main(int argc, char *argv[])
{
int ex = 1, ch, show_usage = 0;
while ((ch = getopt(argc, argv, "vV")) != EOF) {
switch (ch) {
default:
case 'V':
show_usage++;
break;
case 'v':
verbose++;
break;
}/* switch */
}/* while */
if (argc - optind != 2 || show_usage) {
fprintf(stderr, "usage: %s [-v] n m\nCalculate probability of complete n types by m times.\n", argv[0]);
}
else {
int ntypes = strtol(argv[optind], NULL, 0);
int times = strtol(argv[optind + 1], NULL, 0);
printf("%d %d = %.13g\n", ntypes, times, nn_p(ntypes, times));
ex = 0;
}
return ex;
}/* main */