示例#1
0
def main(limit):
	# trick: to maximize phi(n) need n to be a product of two primes, as it can't be prime itself
	minn, minphi = 1, -1
	for p1 in primes.gen():
		if p1 * 3 >= limit:
			break
		p2lim = min(p1, limit / p1)
		for p2 in takewhile(lambda p: p < p2lim, primes.gen()):
			n = p1 * p2
			phi = (p1 - 1) * (p2 - 1)
			if n * minphi < minn * phi and digitCountMap(n) == digitCountMap(phi):
				minn, minphi = n, phi
	return minn
示例#2
0
def main(limit):
    # trick: to maximize phi(n) need n to be a product of two primes, as it can't be prime itself
    minn, minphi = 1, -1
    for p1 in primes.gen():
        if p1 * 3 >= limit:
            break
        p2lim = min(p1, limit / p1)
        for p2 in takewhile(lambda p: p < p2lim, primes.gen()):
            n = p1 * p2
            phi = (p1 - 1) * (p2 - 1)
            if n * minphi < minn * phi and digitCountMap(n) == digitCountMap(
                    phi):
                minn, minphi = n, phi
    return minn
示例#3
0
def group(nums):
	record = dict()
	for n in nums:
		record.setdefault(digitCountMap(n), []).append(n)
	return record.values()