This file contains 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 <bits/stdc++.h> | |
using namespace std; | |
namespace KeyWordArguments{//{{{ | |
template<typename T> | |
class KeyWord {//{{{ | |
using type = T; | |
KeyWord(const size_t &id, const T &val) : id(id), val(val) {} | |
static inline size_t get_id(){ static size_t count = 0; return count++; } | |
public: |
This file contains 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 <bits/stdc++.h> | |
#define all(x) begin(x),end(x) | |
#define rall(x) (x).rbegin(),(x).rend() | |
#define REP(i,b,n) for(int i=(int)(b);i<(int)(n);++i) | |
#define rep(i,n) REP(i,0,n) | |
#define repsz(i,v) rep(i,(v).size()) | |
#define aur auto& | |
#define bit(n) (1LL<<(n)) | |
#define eb emplace_back | |
#define mt make_tuple |
This file contains 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
require "mathn" | |
def f(x) | |
a = [] | |
hash = {} | |
n = 1/x | |
while hash[n].nil? | |
hash[n] = true | |
n *= 10 | |
n -= n.to_i | |
end |
This file contains 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
require "prime" | |
mx = 1000 | |
res = [0, 0, 0] | |
for b in -mx+1...mx | |
next unless b.prime? | |
for a in -mx+1...mx | |
l = 0 | |
l += 1 while (l*l + a*l + b).prime? | |
res = [res, [l, a, b]].max |
This file contains 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
$facto = [1] | |
for i in 1..10 | |
$facto[i] = $facto[i-1] * i | |
end | |
def f(n) | |
res = 0 | |
until n.zero? | |
res += $facto[n%10] | |
n /= 10 | |
end |
This file contains 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
p 1.upto(9999).count{|n| | |
50.times.all?{ | |
n += n.to_s.reverse.to_i | |
n.to_s != n.to_s.reverse | |
} | |
} | |
#=> 249 |
This file contains 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
#!/usr/bin/ruby | |
def f(n) | |
n.to_s.split('').map(&:to_i).inject(0){|a,b|a+b**2} | |
end | |
a = Hash.new do |hash, n| | |
hash[n] = (n == 1 || n == 89) ? n : hash[f(n)] | |
end | |
p 1.upto(1E7).count{|n|a[f(n)] == 89} | |
#=> 8581146 |
This file contains 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
p Hash.new{|hash, n| | |
hash[n] = n.zero? ? 1 : n < 0 ? 0 : (1..4).map{|i|hash[n-i]}.inject(&:+) | |
}[50] | |
#=> 100808458960497 |
This file contains 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> | |
typedef long long ll; | |
using namespace std; | |
const int MOD = (int)(1E9+7); | |
struct MOD_INT{//{{{ | |
int x; | |
MOD_INT(const int &x=0): x((x%MOD+MOD)%MOD){} | |
MOD_INT(const ll &x=0): x((x%MOD+MOD)%MOD){} | |
MOD_INT(const MOD_INT &o): x(o.x){} |
This file contains 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 <cassert> | |
using namespace std; | |
//BEGIN SNIPLATE sum | |
//{{abbr: sum for vector<double>}} | |
//{{class: util, statistics}} | |
//{{pattern: SNIPLATE_SUM}} | |
double sum(vector<double> in) { //SNIPLATE_SUM |