#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define M_PI 3.14159265
int main() {
double a, b, s, shinchi;
int count, m, n;
// 真の値(4つの単位円で囲まれた領域)
shinchi = M_PI - 2.0;
count = 0;
// nの範囲で乱数の試行回数を増やす
for (n = 10; n < 100000; n = n * 5) {
count = 0;
s = 0.0;
for (m = 0; m < n; m++) {
// ランダムな点 (a, b) を生成
a
= (double)rand() / RAND_MAX
; b
= (double)rand() / RAND_MAX
;
// 4つの円に含まれるかチェック
if ((a * a + b * b <= 1.0) && // (0, 0) を中心とする円
((a - 1) * (a - 1) + b * b <= 1.0) && // (1, 0) を中心とする円
(a * a + (b - 1) * (b - 1) <= 1.0) && // (0, 1) を中心とする円
((a - 1) * (a - 1) + (b - 1) * (b - 1) <= 1.0)) { // (1, 1) を中心とする円
s += 1.0;
}
count++;
}
// 面積の推定値
s /= count;
// 誤差の出力
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPG1hdGguaD4KCiNkZWZpbmUgTV9QSSAzLjE0MTU5MjY1CgppbnQgbWFpbigpIHsKICAgIGRvdWJsZSBhLCBiLCBzLCBzaGluY2hpOwogICAgaW50IGNvdW50LCBtLCBuOwoKICAgIC8vIOecn+OBruWApO+8iDTjgaTjga7ljZjkvY3lhobjgaflm7Ljgb7jgozjgZ/poJjln5/vvIkKICAgIHNoaW5jaGkgPSBNX1BJIC0gMi4wOwoKICAgIGNvdW50ID0gMDsKCiAgICAvLyBu44Gu56+E5Zuy44Gn5Lmx5pWw44Gu6Kmm6KGM5Zue5pWw44KS5aKX44KE44GZCiAgICBmb3IgKG4gPSAxMDsgbiA8IDEwMDAwMDsgbiA9IG4gKiA1KSB7CiAgICAgICAgY291bnQgPSAwOwogICAgICAgIHMgPSAwLjA7CgogICAgICAgIGZvciAobSA9IDA7IG0gPCBuOyBtKyspIHsKICAgICAgICAgICAgLy8g44Op44Oz44OA44Og44Gq54K5IChhLCBiKSDjgpLnlJ/miJAKICAgICAgICAgICAgYSA9IChkb3VibGUpcmFuZCgpIC8gUkFORF9NQVg7CiAgICAgICAgICAgIGIgPSAoZG91YmxlKXJhbmQoKSAvIFJBTkRfTUFYOwoKICAgICAgICAgICAgLy8gNOOBpOOBruWGhuOBq+WQq+OBvuOCjOOCi+OBi+ODgeOCp+ODg+OCrwogICAgICAgICAgICBpZiAoKGEgKiBhICsgYiAqIGIgPD0gMS4wKSAmJiAgICAgICAgICAgIC8vICgwLCAwKSDjgpLkuK3lv4PjgajjgZnjgovlhoYKICAgICAgICAgICAgICAgICgoYSAtIDEpICogKGEgLSAxKSArIGIgKiBiIDw9IDEuMCkgJiYgLy8gKDEsIDApIOOCkuS4reW/g+OBqOOBmeOCi+WGhgogICAgICAgICAgICAgICAgKGEgKiBhICsgKGIgLSAxKSAqIChiIC0gMSkgPD0gMS4wKSAmJiAvLyAoMCwgMSkg44KS5Lit5b+D44Go44GZ44KL5YaGCiAgICAgICAgICAgICAgICAoKGEgLSAxKSAqIChhIC0gMSkgKyAoYiAtIDEpICogKGIgLSAxKSA8PSAxLjApKSB7IC8vICgxLCAxKSDjgpLkuK3lv4PjgajjgZnjgovlhoYKICAgICAgICAgICAgICAgIHMgKz0gMS4wOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvdW50Kys7CiAgICAgICAgfQoKICAgICAgICAvLyDpnaLnqY3jga7mjqjlrprlgKQKICAgICAgICBzIC89IGNvdW50OwoKICAgICAgICAvLyDoqqTlt67jga7lh7rlipsKICAgICAgICBwcmludGYoIiVkXHQlZlxuIiwgbiwgZmFicyhzIC0gc2hpbmNoaSkpOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==