示例#1
0
def test1():
    per = 10**5
    core = compute_period_product(per)
    print 'aa',  core
    print 'ref', (factorial(per)/10**prime_factor_expo_of_factorial(per, 5))%per

    print 'result', modexp(core, 10**7, per)
示例#2
0
def compute_period_product(period):
    prod = 1
    niu = prime_factor_expo_of_factorial(period, 5)
     
    for x in xrange(1, period + 1):       
        _, five_rst = partial_factor(x, 5)
        
        x = five_rst
        if niu > 0:
            two_e, two_rst = partial_factor(x, 2)
            if two_e > 0:
                if niu >= two_e:
                    niu -= two_e                    
                    x = two_rst
                else:
                    two_e = two_e - niu
                    niu = 0                    
                    x = two_rst * modexp(2, two_e, period)

        prod = (prod * x) % period        
        # print x, prod 
        
    return prod
示例#3
0
# -*- coding: utf8 -*-
"""
The first known prime found to exceed one million digits was discovered in 1999, and is a Mersenne prime of the form 26972593−1; it contains exactly 2,098,960 digits. Subsequently other Mersenne primes, of the form 2p−1, have been found which contain more digits.

However, in 2004 there was found a massive non-Mersenne prime which contains 2,357,207 digits: 28433×2**7830457+1.

Find the last ten digits of this prime number.
"""

from sieve import modexp

print (28433 * modexp(2, 7830457, 10**10) + 1)%10**10