Пример #1
0
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)
Пример #2
0
def F(n,k=1):
 global c1,c2,sq,mod,max_cache,totSum
 if n == 1:
   return 1
 if n < max_cache:
   return totSum[n]
 if n <= sq and c2[n]:
   return c2[n]
 if k <=sq and c1[k]:
   return c1[k]   
 s = G(n,mod)
# print s,n
 q,div = n/2,2
 while q >= 1:
   r = n % div
   div_next = div + r/q + 1
   s = ( s - (arithmetic(div,1,div_next-div)%mod) * F(n/div,k*div)) % mod
   div = div_next
   q = n/div_next
 if n <= sq:
   c2[n] = s
 if k <=sq:
   c1[k] = s
 return s