Ejemplo n.º 1
0
def m_search(n,k,m=1,phi=1,lowerInd=0):
 global primes,mask,pcap
 s = 0
 if k == 0:
   M = m*phi-phi+m
   bnd = int(M**.25)
   pi = bisect_right(primes,n/m)
   if n/m > pcap:
    f = shanks_factorize(M,primes[:15])
    for d in divisors([[bas,f[bas]] for bas in f]):
     q,r = divmod(d-phi,m-phi)
     if r == 0 and q > primes[lowerInd] and q*m <= n and is_prime(q,pcap-1,mask):
       if (q*m-1) % (q*m - (q-1)*phi) == 0:
        s += q*m
   else:
    for q in primes[lowerInd+1:pi+1]:
     if q*m <= n and (q*m-1) % (q*m - (q-1)*phi) == 0:
      s+= q*m
#        print q*m,q,m
   return s
 bound = int((n/m)**(1./(k+1)))
 i=lowerInd+1
 for i,p in enumerate(primes[lowerInd+1:],lowerInd+1):
   if p > bound:
    break
   else:
    s += m_search(n,k-1,m*p,phi*(p-1),i)
  
 return s   
Ejemplo n.º 2
0
def find_pairs(n):
  global primes,mask
  s = 0
  pairs = {}
  for p in primes[1:]:
   num = p**2-p+1
   f = shanks_factorize(num,primes[:15])
   for k in divisors([[bas,f[bas]] for bas in f] ):
    q = num/k - p + 1
    if q > 0 and q > p and q*p <= n and is_prime(q,pcap-1,mask):
      s += p*q
#      print p,q
      if p not in pairs:
       pairs[p] = [q]
      else:
       pairs[p].append(q)
  print "Sum over semi-primes %d" % s  
  #now do backtracking pair-combos
  for p1 in pairs:
   for p2 in pairs[p1]:
    s += cores_backtrack(n/p1/p2,pairs,[p1,p2])
  return s
Ejemplo n.º 3
0
#f = floor, r = room
def P(f,r):
 if f == 1:
   return r*(r+1) / 2
 k = (r-1)/2
 b = [(f*f) / 2]
 nextSquare = 2*(f/2)+1
 b.append((nextSquare)**2 - b[0])
 b.append((nextSquare+1)**2 - b[1]) 
 
 if r <= 3:
   return b[r-1]
 
 else:
   if not r%2:
     a = b[2] - b[0] + 2
     return b[1] +  pe.arithmetic(a,4,k)
   else:
     a = b[2] - b[0]
     return b[0] + pe.arithmetic(a,4,k)

n = 71328803586048
factors = [(2,27), (3,12)]
s = 0
for f in pe.divisors(factors):
  s = (s + P(f,n/f)) % mod

print s