def test(sols=10**3, np=2, start=2, test=100): t = time() n = 2 z = 2 primes = 2 while z < np: primes *= z z = nextprime(z) while True: for i in range(start, primes * np + 1, primes): #count = numfacts(i**2)//2+1 count = numdivs(i**2) // 2 + 1 if count > test: print('start: ',i,'time:',time()-t,'counts:',count,\ 'test:',test,'next:',np) test += (count // 100 * 100 - test + 100) if count > sols: print(time() - t) print('n: ', i, 'time:', time() - t, 'counts:', count) test += (count // 100 * 100 - test + 100) return i primes *= np np = nextprime(np) start = primes
def e146(top=10 ** 6): ret = 0 x1 = lambda n: n ** 2 + 1 x2 = lambda n: n ** 2 + 3 x3 = lambda n: n ** 2 + 7 x4 = lambda n: n ** 2 + 9 x5 = lambda n: n ** 2 + 13 x6 = lambda n: n ** 2 + 27 test = [x1, x2, x3, x4, x5, x6] mini = 1000 for i in range(1, top + 1): if i > mini: print(i) mini += 1000 z = 0 yesno = i for j in test: y = j(i) if z: if y != z: yesno = 0 break if not isprime2(y): continue z = nextprime(y) ret += yesno return ret
def e146(top=10**6): ret = 0 x1 = lambda n: n**2 + 1 x2 = lambda n: n**2 + 3 x3 = lambda n: n**2 + 7 x4 = lambda n: n**2 + 9 x5 = lambda n: n**2 + 13 x6 = lambda n: n**2 + 27 test = [x1, x2, x3, x4, x5, x6] mini = 1000 for i in range(1, top + 1): if i > mini: print(i) mini += 1000 z = 0 yesno = i for j in test: y = j(i) if z: if y != z: yesno = 0 break if not isprime2(y): continue z = nextprime(y) ret += yesno return ret
def test(sols = 10**3,np=2,start=2,test = 100): t = time() n = 2 z = 2 primes = 2 while z<np:primes*=z;z = nextprime(z) while True: for i in range(start,primes*np+1,primes): #count = numfacts(i**2)//2+1 count = numdivs(i**2)//2+1 if count>test: print('start: ',i,'time:',time()-t,'counts:',count,\ 'test:',test,'next:',np) test+=(count//100*100-test+100) if count>sols: print(time()-t) print('n: ',i,'time:',time()-t,'counts:',count);test+=(count//100*100-test+100) return i primes *=np np = nextprime(np) start = primes
def factors(n): global primes p = primes if n ==1:return [1] if n in p:return [n] else: for i in range(len(p)): if n%p[i]==0: result =[p[i]]+factors(n//p[i])#,primes) return result if isprime2(n):return [n] else: primes+=[nextprime(primes[-1])] return factors(n)#,primes)
def factors(n): global primes p = primes if n == 1: return [1] if n in p: return [n] else: for i in range(len(p)): if n % p[i] == 0: result = [p[i]] + factors(n // p[i]) # ,primes) return result if isprime2(n): return [n] else: primes += [nextprime(primes[-1])] return factors(n) # ,primes)
def e108(sols = 10**3,p = True): t = time() n = 2 np = 1 primes = 2 test = 100 while True: np = nextprime(np) for i in range(primes,primes*np+1,primes): if p:count = numfacts(i**2)//2+1 else:count = numdivs(i**2)//2+1 if count>test: print('n: ',i,'time:',time()-t,'counts:',count,'test: ',test) test+=(count//100*100-test+100) if count>sols: print(time()-t) print('n: ',i,'time:',time()-t,'counts:',count);test+=(count//100*100-test+100) return i primes *=np
def solve(): p = 1 while True: p = nextprime(p) digs = digits(p) numdigs = len(digs) uniquedigs = list(set(digs)) uniquedigs.sort() indexes = [None] * 10 for i in range(numdigs): d = digs[i] if indexes[d] is None: indexes[d] = [] indexes[d].append(i) for d in uniquedigs: # The first member of a family have recurring digits, # each of which is one of 0, 1, and 2. if d > 2: continue inds = indexes[d] # If the number of recurring digits is not a multiple of 3 or # one of the digits is the least significant, then the family # can't have 8 members. if len(inds) % 3 == 0 and inds[-1] != numdigs - 1: start = 1 if inds[0] == 0 else 0 numgenerated = 10 - start numprimes = 0 numcomposites = 0 # Generate family candidates for e in range(start, 10): for i in inds: digs[i] = e number = digits_to_number(digs) if isprime(number): numprimes += 1 else: numcomposites += 1 if numcomposites > numgenerated - 8: break if numprimes == 8: return p
def e108(sols=10**3, p=True): t = time() n = 2 np = 1 primes = 2 test = 100 while True: np = nextprime(np) for i in range(primes, primes * np + 1, primes): if p: count = numfacts(i**2) // 2 + 1 else: count = numdivs(i**2) // 2 + 1 if count > test: print('n: ', i, 'time:', time() - t, 'counts:', count, 'test: ', test) test += (count // 100 * 100 - test + 100) if count > sols: print(time() - t) print('n: ', i, 'time:', time() - t, 'counts:', count) test += (count // 100 * 100 - test + 100) return i primes *= np