Skip to content

Instantly share code, notes, and snippets.

/*
* problem: https://oeis.org/A013990
* algorithm: naive dfs
*
* 4x4 = 323632 => 0.031s
* 5x4 = 11171466 => 1.456s
* 5x5 = 1086297184 => 2m29.479s
*/
#include <iostream>
@qddddr
qddddr / gist:6d5a086967f053e05251
Created May 27, 2015 08:48
my first python program
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
;; 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)
@qddddr
qddddr / 255.cpp
Last active August 29, 2015 14:06
/*
* 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
*/
#!r6rs
;; Project Euler - Problem 255
;;
;; $ time racket 255.sps
;; real 0m11.414s
;; user 0m11.152s
;; sys 0m0.260s
@qddddr
qddddr / 474.cpp
Last active August 29, 2015 14:06
/*
* 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
*/
@qddddr
qddddr / 457.cpp
Last active August 29, 2015 14:06
/*
* 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
*/
/*
* compute sigma[k=1..N] eulerphi(k)
* http://oeis.org/A064018
* http://stackoverflow.com/a/1134851
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
@qddddr
qddddr / 255-test.cpp
Created November 10, 2013 09:34
test uint52_t
#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;
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const int N = 1e5;
vector<int> primes;