示例#1
0
def test(n):
    s = set()
    for i in range(1, n):
        print i, "\r",
        m = prime_cache.isPrime(i)
        for j in range((i + 1) / 4, (i + 1) / 2 + 1):
            if 2 * j < i < 3 * j:
                k = (j, i)
                if m:
                    s.add(k)
                else:
                    s.add(reducedFraction(k))
    #print sorted(s)
    print len(s)
示例#2
0
def test(n) :
	s = set()
	for i in range(1,n) :
		print i, "\r",
		m = prime_cache.isPrime(i)
		for j in range((i+1)/4, (i+1)/2 + 1) :
			if 2*j < i < 3*j :
				k = (j, i)
				if m :
					s.add(k)
				else :
					s.add(reducedFraction(k))
	#print sorted(s)
	print len(s)
示例#3
0
2817 2817 1872 1.50480769231 [3, 3, 313]
2991 2991 1992 1.5015060241 [3, 997]
4435 4435 3544 1.25141083521 [5, 887]
20617 20617 20176 1.02185765266 [53, 389]
45421 45421 44512 1.02042145938 [53, 857]
69271 69271 67912 1.02001119095 [53, 1307]
"""

d = {}
min_so_far = 20000
k = 0
for i in xrange(1000 * 100 * 95, 10, -1):
    ##for i in xrange(1000*1000*10 - 1, 10, -1) :
    ##for i in xrange(10, 1000*1000*10) :
    print i, k, min_so_far, "\r",
    if not prime_cache.isPrime(i):
        p = primes.relativePrimes(i)
        phi = len(p)
        a = sorted(c for c in str(i))
        b = sorted(c for c in str(phi))
        if a == b:
            score = float(i) / float(phi)
            d[i] = phi
            if score < min_so_far:
                k, min_so_far = i, score
                print i, k, phi, min_so_far, primes.primeFactors(i)

print
min_score = min(float(k) / float(v) for k, v in d.iteritems())
for k, v in d.iteritems():
    if v == min_score:
示例#4
0
2817 2817 1872 1.50480769231 [3, 3, 313]
2991 2991 1992 1.5015060241 [3, 997]
4435 4435 3544 1.25141083521 [5, 887]
20617 20617 20176 1.02185765266 [53, 389]
45421 45421 44512 1.02042145938 [53, 857]
69271 69271 67912 1.02001119095 [53, 1307]
"""

d = {}
min_so_far = 20000
k = 0
for i in xrange(1000*100*95, 10, -1) :
##for i in xrange(1000*1000*10 - 1, 10, -1) :
##for i in xrange(10, 1000*1000*10) :
	print i, k, min_so_far, "\r",
	if not prime_cache.isPrime(i) :
		p = primes.relativePrimes(i)
		phi = len(p)
		a = sorted(c for c in str(i))
		b = sorted(c for c in str(phi))
		if a == b :
			score = float(i)/float(phi)
			d[i] = phi
			if score < min_so_far :
				k, min_so_far = i, score
				print i, k, phi, min_so_far, primes.primeFactors(i)

print
min_score = min(float(k) / float(v) for k,v in d.iteritems())
for k,v in d.iteritems() :
	if v == min_score :