This file contains hidden or 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
// this tail recursive implementation can't be optimized by gcc 4.8.1. | |
#include <iostream> | |
#include <vector> | |
#include <cmath> | |
using namespace std; | |
const int N = 1e5; |
This file contains hidden or 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
/* | |
* Project Euler - Problem 156 | |
* | |
* g++ -std=c++11 -O4 156.cpp; time ./a.out | |
* real 0m0.040s | |
* user 0m0.036s | |
* sys 0m0.000s | |
*/ | |
#include <iostream> |
This file contains hidden or 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
/* | |
* Project Euler - Problem 337 (test, O(N^2)) | |
*/ | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <cinttypes> | |
using namespace std; |
This file contains hidden or 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
int main(void) | |
{ | |
const int N = 10, n = 2; | |
enum_coprimes_with_stern_brocot_tree(N, 0, n, n, n); | |
cout << "--------------------" << endl; | |
enum_coprimes_with_reverse_euclid(N, n, n); | |
} |
This file contains hidden or 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
#!r6rs | |
(import (rnrs)) | |
(define (print . args) | |
(for-each display args) | |
(newline)) | |
(define (enum-coprimes/stern-brocot-tree N) | |
(let recur ([a 0] [b 1] [x 1] [y 1]) |
This file contains hidden or 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> | |
using namespace std; | |
void enum_coprimes_with_stern_brocot_tree(int N, int a, int b, int x, int y) | |
{ | |
int n = a+x, d = b+y; | |
if (d <= N) { | |
cout << n << ", " << d << endl; | |
enum_coprimes_with_stern_brocot_tree(N, a, b, n, d); |
This file contains hidden or 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
/* | |
* Project Euler - Problem 441 | |
* Brute forcing and parallelized with OpenMP 3.0 | |
*/ | |
#include <iostream> | |
#include <algorithm> | |
#include <cinttypes> | |
#include <omp.h> | |
#include <boost/multiprecision/cpp_int.hpp> |
This file contains hidden or 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
/* | |
* Project Euler - Problem 441 (Brute forcing) | |
*/ | |
#include <iostream> | |
#include <algorithm> | |
#include <cinttypes> | |
#include <omp.h> | |
#include <boost/multiprecision/cpp_int.hpp> | |
#include <boost/multiprecision/cpp_dec_float.hpp> |
This file contains hidden or 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
#!r6rs | |
;; Project Euler - Problem 401 | |
;; Order = O(sqrt(N)) | |
;; | |
;; $ time racket 401.sps | |
;; ********* | |
;; | |
;; real 0m43.008s | |
;; user 0m41.420s |
This file contains hidden or 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
/* | |
* Project Euler - Problem 432 | |
* A brute force approach with cache-friendly and parallelized implementation. | |
* | |
* $ g++ -std=c++11 -O4 -fopenmp 432.cpp; time ./a.out | |
* N: real user | |
* 1e6: 0.015s 0.076s | |
* 1e7: 0.025s 0.212s | |
* 1e8: 0.138s 1.488s | |
* 1e9: 1.206s 13.368s |