Skip to content

Instantly share code, notes, and snippets.

from math import *
t = input()
for _ in range(t):
a, b = map(int, raw_input().split())
a = ceil(sqrt(a))
b = floor(sqrt(b))
print int(b-a) + 1
private static long factorial(long n) {
long accu = 1;
for (long i = 1; i <= n; i++) {
accu *= i;
}
return accu;
}
@smittyfest
smittyfest / Main.hs
Last active July 14, 2017 14:21 — forked from snoyberg/Main.hs
Comparing iterators, streams, and loops in Haskell, Rust, and C - https://www.fpcomplete.com/blog/2017/07/iterators-streams-rust-haskell
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE TypeFamilies #-}
module Main (main) where
import Foreign
import Foreign.C.Types
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
// both min and max are inclusive
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
// min is inclusive, max is exclusive
return Math.floor(Math.random() * (max - min)) + min;
}
function randomColor() {
return '#'+Math.floor(Math.random()*16777215).toString(16);
}
for (var i = 0; i < 500; i += 13) {
for (var j = 13; j < 480; j += 15) {
context.fillStyle = randomColor();
context.fillText(makeMonster(),i,j);
}
}
@smittyfest
smittyfest / Hilbert.scala
Created June 13, 2017 17:03
Hilbert Curves with Scala Fiddle
import scala.util.Random
case class Point(x: Int, y: Int)
def hilbert(n: Int, d: Int): Point = {
var rx = 0
var ry = 0
var s = 1
var t = d
var p = Point(0, 0)
@smittyfest
smittyfest / subst.clj
Created December 23, 2016 19:23
mutually-recursive functions in Clojure
user=> (declare subst-in-s-exp)
#'user/subst-in-s-exp
user=> (defn subst
#_=> [new old slist]
#_=> (if (empty? slist) ()
#_=> (cons
#_=> (subst-in-s-exp new old (first slist))
#_=> (subst new old (rest slist)))))
#'user/subst
user=> (defn subst-in-s-exp
@smittyfest
smittyfest / list-lengths.clj
Created December 20, 2016 01:24
two ways to compute list-length in Clojure
(defn list-length
[xs]
(if (empty? xs) 0
(+ 1 (list-length (rest xs)))))
(defn list-length2
[xs]
(loop [cnt 0 lst xs]
(if (empty? lst) cnt
(recur (+ 1 cnt)(rest lst)))))