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
/* | |
* problem: https://oeis.org/A013990 | |
* algorithm: naive dfs | |
* | |
* 4x4 = 323632 => 0.031s | |
* 5x4 = 11171466 => 1.456s | |
* 5x5 = 1086297184 => 2m29.479s | |
*/ | |
#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
import cProfile | |
M = 10 ** 10 | |
# O(n) | |
def fibonacci_naive(n): | |
a, b = 0, 1 | |
while 0 < n: | |
a, b = b, (a + b) % M | |
n -= 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
;; http://www.gizmodo.jp/2015/05/8_39.html | |
(use srfi-1) | |
(use util.combinations) | |
;; a + 13 * b / c + d + 12 * e - f - 11 + g * h / i - 10 | |
(define (F a b c d e f g h i) | |
(- (/ (* (+ (- (- (* (+ (+ (/ (* (+ a 13) b) c) d) 12) e) f) 11) g) h) i) 10)) | |
(define (G a b c d e f g h i) |
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 255 | |
* | |
* $ ulimit -s unlimited | |
* $ g++ -std=c++11 -O4 -Wall 255.cpp; time ./a.out | |
* real 0m1.061s | |
* user 0m1.008s | |
* sys 0m0.052s | |
*/ |
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 255 | |
;; | |
;; $ time racket 255.sps | |
;; real 0m11.414s | |
;; user 0m11.152s | |
;; sys 0m0.260s | |
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 474 | |
* DP | |
* | |
* $ g++ -std=c++11 -O4 -Wall 474.cpp; time ./a.out | |
* real 6m23.790s | |
* user 6m23.478s | |
* sys 0m0.008s | |
*/ |
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 457 | |
* Quadratic sieve + exgcd | |
* | |
* $ g++ -std=c++11 -O4 -Wall 457.cpp; time ./a.out | |
* real 0m2.836s | |
* user 0m2.793s | |
* sys 0m0.040s | |
*/ |
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
/* | |
* compute sigma[k=1..N] eulerphi(k) | |
* http://oeis.org/A064018 | |
* http://stackoverflow.com/a/1134851 | |
*/ | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <cmath> |
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> | |
#include <cinttypes> | |
using namespace std; | |
void display(double d) | |
{ | |
const uint64_t u = *reinterpret_cast<uint64_t*>(&d); | |
const auto sign = u >> 63; |
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> | |
#include <vector> | |
#include <cmath> | |
using namespace std; | |
const int N = 1e5; | |
vector<int> primes; |
NewerOlder