Created
June 6, 2021 04:30
-
-
Save fffaraz/f182422068a9e9e9cca6507bdfcd63e5 to your computer and use it in GitHub Desktop.
gcd_prob.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <random> | |
#include <bits/stdc++.h> | |
using namespace std; | |
int main() | |
{ | |
std::random_device m_device{}; | |
std::mt19937 m_generator{m_device()}; | |
std::uniform_int_distribution<int64_t> distribution(1, 100'000'000'000'000); | |
int total = 100'000'000, num = 0; | |
for (int var = 0; var < total; ++var) { | |
int64_t a1 = distribution(m_generator); | |
int64_t a2 = distribution(m_generator); | |
if (std::__gcd(a1, a2) == 1) { | |
num++; | |
} | |
} | |
cout << 1.0 * num / total << "\t" << 6.0 / (M_PI * M_PI) << endl; | |
return 0; | |
} | |
// https://stackoverflow.com/questions/30898575/inbuilt-gcda-b-function-in-c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment