def compute():
	LIMIT = 10**7
	
	smallestprimefactor = eulerlib.list_smallest_prime_factors(LIMIT)
	
	ans = 0
	for i in range(1, LIMIT + 1):
		# Compute factorization as coprime prime powers. e.g. 360 = {2^3, 3^2, 5^1}
		factorization = []
		j = i
		while j != 1:
			p = smallestprimefactor[j]
			q = 1
			while True:
				j //= p
				q *= p
				if j % p != 0:
					break
			factorization.append(q)
		
		solns = [0]
		modulus = 1
		for q in factorization:
			# Use Chinese remainder theorem; cache parts of it
			recip = eulerlib.reciprocal_mod(q % modulus, modulus)
			newmod = q * modulus
			solns = [((0 + (x    ) * recip * q) % newmod) for x in solns] + \
			        [((1 + (x - 1) * recip * q) % newmod) for x in solns]
			modulus = newmod
		
		ans += max(solns)
	return str(ans)
Esempio n. 2
0
def compute():
	LIMIT = 10**7
	
	smallestprimefactor = eulerlib.list_smallest_prime_factors(LIMIT)
	
	ans = 0
	for i in range(1, LIMIT + 1):
		# Compute factorization as coprime prime powers. e.g. 360 = {2^3, 3^2, 5^1}
		factorization = []
		j = i
		while j != 1:
			p = smallestprimefactor[j]
			q = 1
			while True:
				j //= p
				q *= p
				if j % p != 0:
					break
			factorization.append(q)
		
		solns = [0]
		modulus = 1
		for q in factorization:
			# Use Chinese remainder theorem; cache parts of it
			recip = eulerlib.reciprocal_mod(q % modulus, modulus)
			newmod = q * modulus
			solns = [((0 + (x    ) * recip * q) % newmod) for x in solns] + \
			        [((1 + (x - 1) * recip * q) % newmod) for x in solns]
			modulus = newmod
		
		ans += max(solns)
	return str(ans)
Esempio n. 3
0
def compute():
    LIMIT = 10**7

    smallestprimefactor = eulerlib.list_smallest_prime_factors(LIMIT)

    # Maximum size of set of prime factors where the product of the set <= LIMIT.
    # This is important because the number of solutions for n is 2^N,
    # where N is the number of distinct prime factors of n.
    maxnumprimefactors = 0
    prod = 1
    for i in range(2, len(smallestprimefactor)):
        if smallestprimefactor[i] == i:  # i is prime
            if LIMIT // prod < i:
                break
            prod *= i
            maxnumprimefactors += 1

    ans = 0
    # Temporary arrays
    solns = [0] * (2**maxnumprimefactors)
    newsolns = [0] * (2**maxnumprimefactors)
    for i in range(1, LIMIT + 1):
        # Compute factorization as coprime prime powers. e.g. 360 = {2^3, 3^2, 5^1}
        factorization = []
        j = i
        while j != 1:
            p = smallestprimefactor[j]
            q = 1
            while True:
                j //= p
                q *= p
                if j % p != 0:
                    break
            factorization.append(q)

        solns[0] = 0
        solnslen = 1
        modulus = 1
        for q in factorization:
            # Use Chinese remainder theorem; cache parts of it
            recip = eulerlib.reciprocal_mod(q % modulus, modulus)
            newmod = q * modulus

            newsolnslen = 0
            for j in range(solnslen):
                newsolns[newsolnslen] = (0 + (
                    (solns[j] - 0 + modulus) * recip % modulus) * q) % newmod
                newsolnslen += 1
                newsolns[newsolnslen] = (1 + (
                    (solns[j] - 1 + modulus) * recip % modulus) * q) % newmod
                newsolnslen += 1

            solnslen = newsolnslen
            modulus = newmod

            # Flip buffers
            solns, newsolns = newsolns, solns

        ans += max(solns[:solnslen])
    return str(ans)
Esempio n. 4
0
def compute():
    ans = 0
    primes = eulerlib.list_primes(2000000)
    for i in itertools.count(2):
        p = primes[i]
        q = primes[i + 1]
        if p > 1000000:
            break
        k = 1
        while k < p:
            k *= 10
        m = (q - p) * eulerlib.reciprocal_mod(k % q, q) % q
        ans += m * k + p
    return str(ans)
def compute():
	ans = 0
	primes = eulerlib.list_primes(2000000)
	for i in itertools.count(2):
		p = primes[i]
		q = primes[i + 1]
		if p > 1000000:
			break
		k = 1
		while k < p:
			k *= 10
		m = (q - p) * eulerlib.reciprocal_mod(k % q, q) % q
		ans += m * k + p
	return str(ans)
Esempio n. 6
0
def chinese_remainder_theorem(a, p, b, q):
    return (a + (b - a) * eulerlib.reciprocal_mod(p % q, q) * p) % (p * q)
def chinese_remainder_theorem(a, p, b, q):
	return (a + (b - a) * eulerlib.reciprocal_mod(p % q, q) * p) % (p * q)
Esempio n. 8
0
 def s(p):
     return (p - 3) * eulerlib.reciprocal_mod(8 % p, p) % p
Esempio n. 9
0
	def s(p):
		return (p - 3) * eulerlib.reciprocal_mod(8 % p, p) % p