示例#1
0
def run(c, sq):
    run_time = timer()
    if c is None:
        return
    cc = sq[c]
    for b in range(ceil(sqrt(cc / 2)), c + 1):
        if not c & 1 and not b & 1:
            continue
        bb = sq[b]
        gbc = gcd(b, c)
        for a in range(int(sqrt(cc - bb)) + 1, b + 1):
            if (a & 1) + (b & 1) + (c & 1) != 2 or gcd(a, gbc) != 1:
                continue
            aa = sq[a]
            area2 = (aa + bb + cc) * (aa + bb - cc) * (aa - bb +
                                                       cc) * (-aa + bb + cc)
            if is_square(area2):
                area = int(sqrt(area2)) // 4
                print(
                    f'\r{datetime.now().strftime("%Y-%m-%d %H:%M:%S")} - (a={a}², b={b}², c={c}², area={area}) - '
                    f'Heron Triangle with Square Sides!')
                with open('sheron.out', 'a') as f:
                    f.write(f'\ra={a}^2, b={b}^2, c={c}^2, area={area}')
    run_duration = datetime.utcfromtimestamp(timer() - run_time)
    print(
        f'\r{datetime.now().strftime("%Y-%m-%d %H:%M:%S")} - c={c}² - '
        f'Cycle: {run_duration.strftime("%H:%M:%S.%f")[:-3]}',
        end='')
def minX(D):
    if is_square(D):
        return 0
    for frac in sqrtconvergents(D):
        x = frac.numerator
        y = frac.denominator
        if x*x - D*y*y == 1:
            return x
def primegenerating(n):
    if is_square(n):
        return 0
    for div in divisors(
            n
    ):  #unfortunately a generator does not work, as it does not order the divisors, and we would break out of the loop too soon.
        if div * div > n:
            break
        if not isprime(div + (n // div)):
            return 0
    return n
示例#4
0
def sqrtperiod(n):
    if is_square(n) and int(sqrt(n))==sqrt(n): 
        return (int(sqrt(n)),[])
    a0 = floor(sqrt(n))
    a = [a0]
    r = (1,a0)
    for period in count(1):
        denom = n-r[1]*r[1]
        a.append(floor(r[0]*(sqrt(n)+r[1])/denom))
        r = (denom//r[0], (a[-1]*denom-r[0]*r[1])//r[0])
        if periodic(a):
            return (a[0],a[1:])
def sqrtperiod(n):
    if is_square(n): 
        return 0
    a0 = floor(sqrt(n))
    a = [a0]
    r = (1,a0)
    for period in count(1):
        denom = n-r[1]*r[1]
        a.append(floor(r[0]*(sqrt(n)+r[1])/denom))
        r = (denom//r[0], (a[-1]*denom-r[0]*r[1])//r[0])
        if periodic(a):
            #print(f"p({n}) = {period}")
            return period
示例#6
0
def test_is_square():
    assert [i for i in range(25) if is_square(i)] == [0, 1, 4, 9, 16]

    # issue #17044
    assert not is_square(60**3)
    assert not is_square(60**5)
    assert not is_square(84**7)
    assert not is_square(105**9)
    assert not is_square(120**3)
示例#7
0
def fermats_factor(n):
    from sympy import integer_nthroot
    from sympy.ntheory.primetest import is_square
    tmp = integer_nthroot(n, 2)
    a = tmp[0]
    b = pow(a, 2) - n
    k = 0
    bool = tmp[1]

    while not is_square(b):
        a += 1
        b = pow(a, 2) - n

        k += 1

    p = a + integer_nthroot(b, 2)[0]
    q = a - integer_nthroot(b, 2)[0]
    return (p, q)
示例#8
0
def test_is_square():
    assert [i for i in range(25) if is_square(i)] == [0, 1, 4, 9, 16]
示例#9
0
def is_triangle(n):
    return is_square(8 * n + 1)
示例#10
0
def test_is_square():
    assert [i for i in range(25) if is_square(i)] == [0, 1, 4, 9, 16]