#!/usr/bin/python #I A001836 M5429 N2359 #S A001836 53,83,158,263,293,368,578,683,743,788,878,893,908,998,1073,1103,1208, #T A001836 1238,1268,1403,1418,1502,1523,1658,1733,1838,1943,1964,2048,2063, #U A001836 2153,2228,2243,2258,2363,2393,2423,2468,2558,2573,2633,2657,2678 #N A001836 phi(2n-1) < phi(2n). #o A001836 Python program by Don Reble (djr(AT)nk.ca), Jan 04 2007 # primes to 1000 SmallPrimes = ( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 ) # the least number unfactorable by that list of primes Unfactorable = 1009 * 1009 # This function gives the quantity of numbers less than nn and coprime to nn # (provided that nn < Unfactorable). def phi(nn): coprQuan = nn # this many potentially coprime numbers, # from 1 to nn for pr in SmallPrimes: # each potential prime factor of nn if nn < pr*pr: break; # nn is prime or 1: stop factoring. if (nn % pr) == 0: # Is pr a factor? coprQuan -= coprQuan / pr # Multiples of pr aren't coprime. *(see below) nn /= pr # Divide out pr... while (nn % pr) == 0: nn /= pr # ...until it's not a factor. if nn > 1: # Is nn prime? coprQuan -= coprQuan / nn # Multiples of nn aren't coprime. *(see below) return coprQuan # *This is subtler than it looks. The number of multiples of pr is # (the-original-nn / pr). But many were already discounted when # applying previous prime factors. It works out, that the proportion of # pr-multiples remains constant throughout, and so (coprQuan / pr) is # the right number to subtract. termQuan = 100 # Make this many terms. num = 1 # Test numbers starting from 1. while termQuan > 0: # while more terms to make dblnum = num + num if dblnum >= Unfactorable: break; # Can't make more terms. :-( # Must expand SmallPrimes, # increase Unfactorable. if phi(dblnum-1) < phi(dblnum): # Is num in the sequence? print num, termQuan -= 1 num += 1 # next number