Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
gcd_prob.cpp
#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