def elemop(N=1000):
    r'''
    (Takes about 40ms on a first-generation Macbook Pro)
    '''
    for i in range(N):
        assert a+b == 579
        assert a-b == -333
        assert b*a == a*b == 56088
        assert b%a == 87
        assert divmod(a, b) == (0, 123)
        assert divmod(b, a) == (3, 87)
        assert -a == -123
        assert pow(a, 10) == 792594609605189126649
        assert pow(a, 7, b) == 99
        assert cmp(a, b) == -1
        assert '7' in str(c)
        assert '0' not in str(c)
        assert a.sqrt() == 11
        assert _g.lcm(a, b) == 18696
        assert _g.fac(7) == 5040
        assert _g.fib(17) == 1597
        assert _g.divm(b, a, 20) == 12
        assert _g.divm(4, 8, 20) == 3
        assert _g.divm(4, 8, 20) == 3
        assert _g.mpz(20) == 20
        assert _g.mpz(8) == 8
        assert _g.mpz(4) == 4
        assert a.invert(100) == 87
示例#2
0
def elemop(N=1000):
    r'''
    (Takes about 40ms on a first-generation Macbook Pro)
    '''
    for i in range(N):
        assert a + b == 579
        assert a - b == -333
        assert b * a == a * b == 56088
        assert b % a == 87
        assert divmod(a, b) == (0, 123)
        assert divmod(b, a) == (3, 87)
        assert -a == -123
        assert pow(a, 10) == 792594609605189126649
        assert pow(a, 7, b) == 99
        assert cmp(a, b) == -1
        assert '7' in str(c)
        assert '0' not in str(c)
        assert a.sqrt() == 11
        assert _g.lcm(a, b) == 18696
        assert _g.fac(7) == 5040
        assert _g.fib(17) == 1597
        assert _g.divm(b, a, 20) == 12
        assert _g.divm(4, 8, 20) == 3
        assert _g.divm(4, 8, 20) == 3
        assert _g.mpz(20) == 20
        assert _g.mpz(8) == 8
        assert _g.mpz(4) == 4
        assert a.invert(100) == 87
示例#3
0
def fibo(n):
    """
    nth Fibonacci number.
    See fibonacci how to implement this.
    """
    return gmpy.fib(n)
示例#4
0
    def apply(self, n, evaluation):
        'Fibonacci[n_Integer]'

        return Integer(fib(n.value))
示例#5
0
文件: euler_25.py 项目: shano/Euler
def main(digits):
    i = 0
    while len(str(gmpy.fib(i))) != 1000:
        i += 1

    print i
示例#6
0
 def apply(self, n, evaluation):
     'Fibonacci[n_Integer]'
     
     return Integer(fib(n.value))
示例#7
0
def timedfibsp(n, one):
    start=time.clock()
    result=gmpy.fib(n)
    stend=time.clock()
    return type(one), stend-start, result
示例#8
0
def fibo(n):
    """
    nth Fibonacci number.
    See fibonacci how to implement this.
    """
    return gmpy.fib(n)
import gmpy as _g
import time

print "Typical expected results would be:","""
D:\PySym>python timing.py
Factorial of 10000 took 0.0619989238859 (35660 digits)
Fibonacci of 10000 took 0.000744228458022 (2090 digits)
Factorial of 100000 took 4.44311764676 (456574 digits)
Fibonacci of 100000 took 0.022344453738 (20899 digits)
Factorial of 1000000 took 152.151135367 (5565709 digits)
Fibonacci of 1000000 took 0.670207059778 (208988 digits)
"""

print "Actual timings and results...:"
for i in (10000,100000,1000000):
    start=time.clock()
    x=_g.fac(i)
    stend=time.clock()
    print "Factorial of %d took %s (%d digits)" % (
        i, stend-start, x.numdigits())

    start=time.clock()
    x=_g.fib(i)
    stend=time.clock()
    print "Fibonacci of %d took %s (%d digits)" % (
        i, stend-start, x.numdigits())

示例#10
0
#!/usr/bin/env python3

import gmpy

# find base-2 psuedoprimes

for n in range(3, 1 << 24, 2):

    # 3
    if n % 5 not in [2, 3]:
        continue

    # 1
    if pow(2, n, n) != 2:
        continue

    # 4
    if gmpy.is_prime(n):
        continue

    # 2
    fres = gmpy.fib(n + 1) % n
    if fres != 0:
        continue

    print("OMG OMG OMG", n)
    #exit(0)