def check(x,y): if x > 2*y: return False d = pe.gcd(x,y) x/=d y/=d its = 0 while y > 1: if x >= 2*y : return its%2 x -= y its += 1 x,y = max(x,y), min(x,y) # print x,y return its%2
cap = 10**12 mod = 10**5 t = 1 while t <= cap: t5 = 1 while t*t5 <= cap: h.append(t*t5) t5 *= 5 t *= 2 o2 = prime_fact_ord(2,cap) o5 = prime_fact_ord(5,cap) exp2 = o2-o5 #Significant exponent of 2 in final product h = sorted(h) #numbers divisible only by 2 and 5 print len(h) res = 1 #init to one for i in xrange(1,min(cap+1,mod)): if gcd(i,10) == 1: e = 0 #the exponent by i in the final product for m in h: if m*i > cap: break max_r = ((cap/m) - i) / mod #maximum r with m*(r*mod+i) <= cap e += max_r+1 res = (res * pow(i,e,mod)) % mod res = (res * pow(2,exp2,mod)) % mod print res
primes,mask = pe.primes_and_mask(cap) curr = np.ones(cap,dtype=np.int64) for croak in croaks: prev = curr curr = np.ones(cap,dtype=np.int64) #Count croaks multiplicities. For each path on a prime, P gets croaked twice #For each on a non-prime, N gets croaked twice if croak == "P": for i in xrange(cap): if mask[i+1]: prev[i] *= 2 else: for i in xrange(cap): if not mask[i+1]: prev[i] *= 2 #compute transitions curr[1:cap-1] = prev[:cap-2] + prev[2:cap] curr[0] = prev[1] curr[cap-1] = prev[cap-2] #double count the contributions from the end squares curr[1] += prev[0] curr[cap-2] += prev[cap-1] num = np.sum(prev) print "Total admissible possibilities " + str(num) d = pe.gcd(denom,num) print "Reduced fraction " + str(num/d) + "/" + str(denom/d)