def sum_isqrt(a,b): """ Returns the sum of the integer part of sqrt(i) for i in xrange(a,b) But this is O(log(b)) (for the isqrt computation) a and b are positive integers, b > a. """ ia,ib = isqrt(a),isqrt(b) if ia==ib: return ia*(b-a) return ia*((ia+1)**2-a) + ib*(b-(ib)**2) + lin_sum(ib-1)-lin_sum(ia) + 2*(square_sum(ib-1)-square_sum(ia))
def solve(n): """ Solve PE problem 325 for n. """ tot = 0 fibs = pe.fibb(n) print zip(fibs[1:-1], fibs[2:]) cands = set() phi = (5**.5+1)/2 for x in xrange(1,n+1): fl = int(x/phi) # tot += x*(x-fl-1) + (x*(x-1)-(fl)*(fl+1)) / 2 tot += x*(-fl) + (-(fl)*(fl+1)) / 2 # for f1, f2 in zip(fibs[1:-1], fibs[2:]): # if abs(f2*y-f1*x) == pe.gcd(x,y): # cands.add((x,y)) return tot + 3*pe.square_sum(n)/2 + pe.lin_sum(n)/2