Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- int main() {
- uint64_t in_count = 0;
- uint32_t N = 1000*100*2;
- for (uint32_t i = 0 ; i < N ; i++) {
- in_count += N-i-1;
- const auto y = static_cast<double>(i)/N;
- for (uint32_t j = N-i ; j < N ; j++) {
- const auto x = static_cast<double>(j)/N;
- if ((x*x + y*y) < 1) {
- in_count ++;
- }
- }//std::cout << std::endl;
- }
- std::cout << in_count << std::endl;
- double four = 4;
- std::cout << std::fixed; std::cout.precision(10);
- std::cout << (four*in_count / N) << std::endl;
- return 0;
- }
- #include <iostream>
- #include <random>
- int main() {
- uint64_t in_count = 0;
- uint32_t N = 1000*100*2;
- for (uint32_t i = 0 ; i < N ; i++) {
- //in_count += N-i-1;
- const auto y = static_cast<double>(i)/N;
- for (uint32_t j = N-i ; j < N ; j++) {
- const auto x = static_cast<double>(j)/N;
- if ((x*x + y*y) >= 1) {
- in_count += j-1;
- break;
- }
- }//std::cout << std::endl;
- }
- std::cout << in_count << std::endl;
- double four = 4;
- std::cout << std::fixed; std::cout.precision(10);
- std::cout << (four*in_count / N) << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement