#include <stdio.h>
#include <stdlib.h>
double monte_carlo_e(int n) {
int count = 0;
for (int i = 0; i < n; i++) {
double sum = 0.0;
int k = 0;
while (sum < 1.0) {
sum
+= (double)rand() / RAND_MAX
; k++;
}
count += k;
}
return (double)count / n;
}
int main() {
int n = 1000000; // 試行回数
double e_approx = monte_carlo_e(n);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmRvdWJsZSBtb250ZV9jYXJsb19lKGludCBuKSB7CiAgICBpbnQgY291bnQgPSAwOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBkb3VibGUgc3VtID0gMC4wOwogICAgICAgIGludCBrID0gMDsKICAgICAgICB3aGlsZSAoc3VtIDwgMS4wKSB7CiAgICAgICAgICAgIHN1bSArPSAoZG91YmxlKXJhbmQoKSAvIFJBTkRfTUFYOwogICAgICAgICAgICBrKys7CiAgICAgICAgfQogICAgICAgIGNvdW50ICs9IGs7CiAgICB9CiAgICByZXR1cm4gKGRvdWJsZSljb3VudCAvIG47Cn0KCmludCBtYWluKCkgewogICAgaW50IG4gPSAxMDAwMDAwOyAvLyDoqabooYzlm57mlbAKICAgIGRvdWJsZSBlX2FwcHJveCA9IG1vbnRlX2NhcmxvX2Uobik7CiAgICBwcmludGYoIiVmXG4iLCBlX2FwcHJveCk7CiAgICByZXR1cm4gMDsKfQ==