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
{-# OPTIONS_GHC -O2 -XNoMonomorphismRestriction #-} | |
{-# LANGUAGE BangPatterns #-} | |
{-(c) gorlum0 [at] gmail.com-} | |
isqrt x = truncate (sqrt $ fromIntegral x) | |
isPrime n | |
| n`rem`2 == 0 = False | |
| otherwise = null [x | x <- [3,5.. isqrt n + 1], n`rem`x == 0] |
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
{-# OPTIONS_GHC -O2 -XNoMonomorphismRestriction #-} | |
{-# LANGUAGE BangPatterns #-} | |
{-(c) gorlum0 [at] gmail.com-} | |
import Control.Monad (forM_) | |
triangular = takeWhile (<=500) $ scanl1 (+) [1..] | |
main = do | |
ls <- lines `fmap` getContents | |
let xs = map read ls |
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
#!/usr/bin/env python | |
"""(c) gorlum0 [at] gmail.com""" | |
import re | |
import string | |
from math import log | |
from sys import stdin | |
def int2base(x, base, digits = '0123456789abcdefghijklmnopqrstuvwxyz'): | |
'''inverse of int(x, base), 2 <= base <= 36''' | |
if x < 0: |
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
{-# OPTIONS_GHC -O2 -XNoMonomorphismRestriction #-} | |
{-# LANGUAGE BangPatterns #-} | |
{-(c) gorlum0 [at] gmail.com-} | |
import qualified Data.Map as M | |
import qualified Data.Set as S | |
splitEvery _ [] = [] | |
splitEvery n xs = ys : splitEvery n xs' | |
where (ys, xs') = splitAt n xs |
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
{-# OPTIONS_GHC -O2 -XNoMonomorphismRestriction #-} | |
{-# LANGUAGE BangPatterns #-} | |
{-(c) gorlum0 [at] gmail.com-} | |
import Data.Array | |
import Control.Monad (forM_) | |
maxn = 10^6 | |
dp :: Array Int Int | |
dp = array bnds [(i, f i) | i <- range bnds] | |
where |
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
#!/usr/bin/env python2.6 | |
"""(c) gorlum0 [at] gmail.com""" | |
from sys import stdin | |
MAXN = 10**6 | |
dp = [0] * (MAXN+1) | |
dp[0] = 1 | |
for i in xrange(MAXN+1): | |
if dp[i-7]: |
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 java.io.*; | |
import java.util.*; | |
import java.math.*; | |
public class NetworkXOneTimePad | |
{ | |
Long[] convert(String[] arr) { | |
int n = arr.length; | |
Long[] res = new Long[n]; | |
for (int i = 0; i < n; 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
#!/usr/bin/env python | |
"""(c) gorlum0 [at] gmail.com""" | |
import itertools as it | |
from sys import stdin | |
maxn = 10**5 | |
def get_divisors(n, _cache = {}): | |
if n not in _cache: | |
divisors = [] | |
for i in xrange(1, int(n**0.5) + 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
import java.io.*; | |
import java.util.*; | |
import java.math.*; | |
public class CompositeSmash | |
{ | |
HashMap<Integer, Boolean> _cache = new HashMap(); | |
boolean possible(int n, int t) { | |
if (n < t) return false; | |
if (n == t) return true; |
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
/*(c) gorlum0 [at] gmail.com*/ | |
import java.io.*; | |
import java.util.*; | |
import java.math.*; | |
public class NetworkXMessageRecovery | |
{ | |
public String recover(String[] messages) { | |
StringBuilder res = new StringBuilder(); |