#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int N = 100000; // N: 抽樣的數量
int m = 0; // M: 落在四分之一圓的點數
for (int i = 1; i <= N; i++) {
double x = (double) rand() / RAND_MAX;
double y = (double) rand() / RAND_MAX;
if (x * x + y * y < 1) {
m++; //若該點落在四分之一內則 M++
}
}
cout << "pi~ " << 4.0 * m / N << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGN0aW1lPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJCglpbnQgTiA9IDEwMDAwMDsgICAvLyBOOiDmir3mqKPnmoTmlbjph48KCWludCBtID0gMDsgICAgICAgIC8vIE06IOiQveWcqOWbm+WIhuS5i+S4gOWck+eahOm7nuaVuAoJZm9yIChpbnQgaSA9IDE7IGkgPD0gTjsgaSsrKSB7CgkJCgkJZG91YmxlIHggPSAoZG91YmxlKSByYW5kKCkgLyBSQU5EX01BWDsKCQlkb3VibGUgeSA9IChkb3VibGUpIHJhbmQoKSAvIFJBTkRfTUFYOwoJCQoJCWlmICh4ICogeCArIHkgKiB5IDwgMSkgewoJCQltKys7ICAgLy/oi6XoqbLpu57okL3lnKjlm5vliIbkuYvkuIDlhafliYcgTSsrCgkJfQoJCQoJfQoJY291dCA8PCAicGl+ICIgPDwgNC4wICogbSAvIE4gPDwgZW5kbDsKCXJldHVybiAwOwp9