''' Created on Jan 28, 2013 @author: kan ''' import itertools import src.solution.Mytools as Mt def pr(n): sum = 0 s = set(range(1, n+1)) for i in range(1, ((n-1)>>1)+1): ''' the case that no red disc is picked will be added at last''' blue = itertools.combinations(s, i) for j in blue: p = 1 for k in j: p *= k sum += p return sum + 1 print(Mt.factorial(16)/pr(15))
''' Created on Mar 31, 2014 @author: kan ''' import src.solution.Mytools as Mt N = 100000 primes = Mt.primes2(N) def compute_r(n): if n==0 or n==1: return n rad = 1 for p in primes: if n%p == 0: rad *= p n//=p while n % p == 0: n //= p if n==1: return rad class radical: def __init__(self, n): self.n = n self.r = compute_r(n) def __lt__(self, rad2): return self.r < rad2.r or self.r==rad2.r and self.n < rad2.n class ordered_radicals:
""" Created on Mar 29, 2013 @author: kan """ import src.solution.Mytools as Mt primes = Mt.primes2(1000003) def S(p1, p2): l = len(str(p2)) dig = 10 ** l p = p2 while p % dig != p1: p += p2 return p sum = 0 for i in range(2, len(primes) - 1): sum += S(primes[i], primes[i + 1]) print(sum)
""" Created on Jan 27, 2013 @author: kan """ import src.solution.Mytools as Mt import math logs = [20000] * 500 for i in range(3, len(logs)): logs[i] = math.log(i) clogs = list(logs) power = [1] * 500 """clogs is the list of log of power numbers""" i = 0 while i < 37: min_index = clogs.index(min(clogs)) number = min_index ** power[min_index] l = Mt.num2list(number) x = 0 for j in l: x += int(j) if x == min_index: print(number) i += 1 clogs[min_index] += logs[min_index] power[min_index] += 1
""" Created on Mar 31, 2014 @author: kan make sure that all numbers added are unique """ import src.solution.Mytools as Mt n = 10001 bound = 10 ** 8 def f(n): return n * (n + 1) * (2 * n + 1) // 6 squre_sums = [f(i) for i in range(n)] nset = set() ans = 0 for i in range(2, n): for j in range(i - 1): s = squre_sums[i] - squre_sums[j] if s < bound and Mt.isPalindromic(str(s)): nset.add(s) print(sum(nset))