예제 #1
0
def findx(D):
    sqrtD = sqrt(D)
    if sqrtD * sqrtD == D:
        return 0
    seq = makesequence(D)
    for x, y in makeconvergents(seq):
        if x * x - D * y * y == 1:
            return x
예제 #2
0
def makesequence(D):
    floor = sqrt(D)
    seq = []
    a = -floor
    c = 1
    while True:
        x, aa, cc = makenext(a, c, D)
        seq.append(x)
        if x == 2 * floor: break
        a = aa
        c = cc
    return chain([floor], cycle(seq))
예제 #3
0
def main():
    print('HELLO WORLD')
    N = 1500000
    p = [0] * (N + 1)
    for m in range(2, sqrt(N)):
        for n in range(1, m):
            if gcd(m, n) > 1: continue
            if m % 2 and n % 2: continue
            k = 1
            while k * (2 * m * m + 2 * m * n) <= N:
                p[k * (2 * m * m + 2 * m * n)] += 1
                k += 1
    ans = 0
    for count in p:
        if count == 1:
            ans += 1
    return ans
예제 #4
0
def makenext(a, c, D):
    newc = (D - a**2) // c
    newa = -a
    x = ((newa + sqrt(D)) // newc)
    newa -= x * newc
    return x, newa, newc
예제 #5
0
def isSquare(num):
    if sqrt(num)**2 == num:
        return True
예제 #6
0
from collections import *
from itertools import *
from random import *
from time import *
from functools import *
from fractions import *
from math import *
from pe_lib import PrimeSieve, sqrt
'''

'''
n = 5 * 10**7
a = PrimeSieve(sqrt(n)).primes


def main():
    ans = set()
    for i in a:
        ii = i * i
        for j in a:
            jjj = j * j * j
            if ii + jjj >= n: break
            for k in a:
                s = ii + jjj + k * k * k * k
                if s < n:
                    ans.add(s)
                else:
                    break
    print(len(ans))