Ejemplo n.º 1
0
def GetCommonMul(arr):
    _, primes = PrimeUtil.get_prime_dic_and_list(arr[len(arr) - 1])
    ans = {}
    for i in range(len(arr)):
        t = arr[i]
        index = 0
        while t != 1 and index < len(primes):
            if t % primes[index] == 0:
                num = 0
                while t % primes[index] == 0:
                    num += 1
                    t //= primes[index]

                if primes[index] not in ans:
                    ans[primes[index]] = 1

                ans[primes[index]] = max(ans[primes[index]], num * 2)

            index += 1

    #print(ans)
    ret = 1
    for k, v in ans.items():
        ret *= pow(k, v)

    return ret
Ejemplo n.º 2
0
def GetMayKeys(n):
    _, primes = PrimeUtil.get_prime_dic_and_list(n)
    ret = []
    tR = set()
    for i in range(2, n + 1):
        if i in primes and i * 2 > n:
            continue

        if i in primes:
            k = n // i
            #print(i, k)
            if k < i:
                if GetSumP(k, i):
                    for j in range(2, k + 1):
                        tR.add(j * i)
                    continue

        ret.append(i)
    for v in tR:
        ret.remove(v)
    #print(ret)
    return ret
Ejemplo n.º 3
0
    now = 1
    index = 1
    while True:
        if now % n == 0:
            return True, index
        else:
            if now in uni:
                return False, None
            
            uni[now] = True
            index += 1
            
            now = now%n
            now = now*10 + 1

_, primes = PrimeUtil.get_prime_dic_and_list(1000000)
#print(primes)

target = 1000000000

ans = 0
cc = 0
for i in range(len(primes)):
    flag, n = CanPrimeBeFactor(primes[i])
    #print(i,primes[i],flag,n)
    if flag and target % n == 0:
        ans += primes[i]
        cc += 1
        print(cc,primes[i])
    #print(cc)
    if cc >= 40:
Ejemplo n.º 4
0

def FindN(p1, p2, pre=0):
    for i in range(10):
        sm = p2 * i + pre
        if sm % 10 == p1 % 10:
            if p1 // 10 == 0:
                return True, i
            else:
                testMin, div = FindN(p1 // 10, p2, sm // 10)
                if testMin:
                    return True, div * 10 + i

    return False, None


_, primeList = PrimeUtil.get_prime_dic_and_list(1001000)

Nsum = 0
for i in range(len(primeList)):
    if primeList[i] > 1000000:
        breakpoint
    elif primeList[i] >= 5:
        flag, divsor = FindN(primeList[i], primeList[i + 1], 0)
        if flag:
            Nsum += primeList[i + 1] * divsor
        else:
            print(primeList[i], None)

print(Nsum)
Ejemplo n.º 5
0
import sys
sys.path.append("..")
from Common import PrimeUtil

#limit = 30
limit = pow(10, 8)
_, primeList = PrimeUtil.get_prime_dic_and_list(limit)

print("Start Cal:")
head = 0
end = len(primeList) - 1
ans = 0
while head < end:
    while head <= end and primeList[head] * primeList[end] >= limit:
        end -= 1
    if head > end:
        break
    #print(primeList[head], primeList[end])
    ans += (end - head + 1)
    head += 1

print(ans)