def pe169(n, k=None): if n < 0: return 0 if n <= 1: return 1 k2 = int(log(n, 2)) if k is None: k = k2 elif k < k2 - 1: return 0 else: k = min(k, k2) if k == 0: return 1 if n < 3 else 0 kmax = 2 ** k return pe169(n, k-1)+pe169(n-kmax, k-1)+pe169(n-kmax*2, k-1)
def pe169(n, k=None): if n < 0: return 0 if n <= 1: return 1 k2 = int(log(n, 2)) if k is None: k = k2 elif k < k2 - 1: return 0 else: k = min(k, k2) if k == 0: return 1 if n < 3 else 0 kmax = 2**k return pe169(n, k - 1) + pe169(n - kmax, k - 1) + pe169( n - kmax * 2, k - 1)
#!/usr/bin/python # -*- coding: utf-8 -*- #2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. #What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? #Answer: #232792560 from time import time; t=time() from mathplus import prime, log NUM = 20 n = NUM logn = log(NUM) ret = 1 for p in prime(): if p > n: break ret *= p**int(logn/log(p)) print(ret)#, time()-t
#!/usr/bin/python # -*- coding: utf-8 -*- #2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. #What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? #Answer: #232792560 from time import time t = time() from mathplus import prime, log NUM = 20 n = NUM logn = log(NUM) ret = 1 for p in prime(): if p > n: break ret *= p**int(logn / log(p)) print(ret) #, time()-t