示例#1
0
def solution():
    DIGITS = 100
    MULTIPLIER = 100**DIGITS
    result = sum(
        sum(int(c) for c in str(common.sqrt(i * MULTIPLIER))[:DIGITS])
        for i in range(100) if common.sqrt(i)**2 != i)
    return str(result)
示例#2
0
def solution():
	goal = 2000000
	end = common.sqrt(goal) + 1
	gen = ((w, h) for w in range(1, end) for h in range(1, end))
	func = lambda wh: abs(num_rectangles(*wh) - goal)
	result = min(gen, key=func)
	return str(result[0] * result[1])
示例#3
0
	def floor(self):
		temp = common.sqrt(self.b * self.b * self.d)
		if self.b < 0:
			temp = -(temp + 1)
		temp += self.a
		if temp < 0:
			temp -= self.c - 1
		return temp // self.c
示例#4
0
def divisorCount(n):
    count = 1
    end = common.sqrt(n)
    for i in itertools.count(2):
        if i > end:
            break
        if n % i == 0:
            j = 0
            while True:
                n //= i
                j += 1
                if n % i != 0:
                    break
            count *= j * 2 + 1
            end = common.sqrt(n)
    if n != 1:
        count *= 3
    return count
示例#5
0
def stdev(X,axis=1):
    assert(dim(X)==2)
    assert(axis==1)
    X_T = matrix_transpose(X)
    m = mean(X,axis=1)
    R = []
    for j in range(shape(X)[1]):
        R.append(sqrt(mean(square(minus(X_T[j],m[j])))))
    return R
示例#6
0
    def _corr(A,i,j):
        assert(dim(A)==2)
        m,n = shape(A)
        A_T = matrix_transpose(A)
        
        X,Y = A_T[i],A_T[j] # X,Y = col(A,i),col(A,j)

        mean_X,mean_Y = mean(X),mean(Y)
        X_ = [k-mean_X for k in X]
        Y_ = [k-mean_Y for k in Y]
        numerator = mean(multiply(X_,Y_))
        # print(sqrt(mean(square(X_))))

        denominator = sqrt(mean(square(X_)))*sqrt(mean(square(Y_)))
        if denominator == 0:
            return 0
        else:
            r = (numerator)/(denominator)
            return r
示例#7
0
def solution():
    ceiling = 50000000
    primes = common.list_primes(common.sqrt(ceiling))

    sums = {0}
    for i in range(2, 5):
        newsums = set()
        for p in primes:
            q = p**i
            if q > ceiling:
                break
            for x in sums:
                if x + q <= ceiling:
                    newsums.add(x + q)
        sums = newsums
    return str(len(sums))
示例#8
0
	def is_prime(x):
		if x < 0:
			raise ValueError()
		elif x in (0, 1):
			return False
		else:
			end = common.sqrt(x)
			for p in primes:
				if p > end:
					break
				if x % p == 0:
					return False
			for i in range(primes[-1] + 2, end + 1, 2):
				if x % i == 0:
					return False
			return True
示例#9
0
def solution():
    x0 = 3
    y0 = 1

    x = x0
    y = y0
    while True:
        sqrt = common.sqrt(y**2 * 8 + 1)
        if sqrt % 2 == 1:  # Is odd
            blue = (sqrt + 1) // 2 + y
            if blue + y > 10**12:
                return str(blue)

        nextx = x * x0 + y * y0 * 8
        nexty = x * y0 + y * x0
        x = nextx
        y = nexty
示例#10
0
def solution():
    ceiling = 1500000
    triples = set()
    for s in range(3, common.sqrt(ceiling) + 1, 2):
        for t in range(s - 2, 0, -2):
            if fractions.gcd(s, t) == 1:
                a = s * t
                b = (s * s - t * t) // 2
                c = (s * s + t * t) // 2
                if a + b + c <= ceiling:
                    triples.add((a, b, c))

    ways = [0] * (ceiling + 1)
    for triple in triples:
        sigma = sum(triple)
        for i in range(sigma, len(ways), sigma):
            ways[i] += 1

    result = ways.count(1)
    return str(result)