# Introduction: # A deletable composite is a composite number with two or more digits # that remains composite when any digit is deleted. For example, 104 # is a deletable composite because 10, 14, and 04 are composite. # Note that leading zeros are allowed. # # The following Python 2.7 code computes a list of all deletable composites # up to a given bound. It is intended as a supplement for Sequence A225619 # in the On-line Encyclopedia of Integer Sequences. The sequence was authored # by Derek Orr. # # The code for the Sieve of Eratosthenes is copied from # http://stackoverflow.com/questions/1023768/sieve-of-atkin-explanation # but I cannot find the original author. # # All other code was written by David Radcliffe and is released to the public domain. # If you use this code, attribution is appreciated but not required. from math import sqrt N = 1000 sqrtN = int(sqrt(N))+1 def sieveOfErat(end): if end < 2: return [] #The array doesn't need to include even numbers lng = ((end/2)-1+end%2) # Create array and assume all numbers in array are prime sieve = [True]*(lng+1) # In the following code, you're going to see some funky # bit shifting and stuff, this is just transforming i and j # so that they represent the proper elements in the array. # The transforming is not optimal, and the number of # operations involved can be reduced. # Only go up to square root of the end for i in range(int(sqrt(end)) >> 1): # Skip numbers that aren't marked as prime if not sieve[i]: continue # Unmark all multiples of i, starting at i**2 for j in range( (i*(i + 3) << 1) + 3, lng, (i << 1) + 3): sieve[j] = False # Don't forget 2! primes = [2] # Gather all the primes into a list, leaving out the composite numbers primes.extend([(i << 1) + 3 for i in range(lng) if sieve[i]]) return primes primes = sieveOfErat(sqrtN) # isprime(n) returns True if n is prime, and False if n is not prime. # The function assumes that the input is an integer. # If n is greater than N*N but it has no prime factor less than or equal to N, # then the function will return None, indicating that the function is unable # to determine if n is prime. def isprime(n): if n <= sqrtN and n in primes: return True if any(n % p == 0 for p in primes): return False if n <= N: return True # iscomposite(n) returns True if n is composite, and it returns False if n is prime # or if n is less than 4. A value of None indicates that the function is unable # to determine if n is composite. def iscomposite(n): if n < 4 or isprime(n): return False if n <= N: return True # Generator which returns the numbers obtained by n by deleting one digit. # For example, deleteOneDigit(123) yields 23, 13, and 12. def deleteOneDigit(n): s = str(n) for k in xrange(len(s)): yield int(s[:k] + s[k+1:]) # This function returns True if n is a deletable composite number, False otherwise. def deletableComposite(n): return iscomposite(n) and all(iscomposite(d) for d in deleteOneDigit(n)) # List all deletable composites up to N. print filter(deletableComposite, xrange(10,N+1))
Standard input is empty
[44, 46, 48, 49, 64, 66, 68, 69, 84, 86, 88, 94, 96, 98, 99, 104, 106, 108, 120, 122, 124, 125, 126, 128, 140, 142, 144, 145, 146, 148, 150, 152, 154, 155, 156, 158, 160, 162, 164, 165, 166, 168, 180, 182, 184, 185, 186, 188, 204, 206, 208, 210, 212, 214, 215, 216, 218, 220, 221, 222, 224, 225, 226, 228, 240, 242, 244, 245, 246, 248, 250, 252, 254, 255, 256, 258, 260, 262, 264, 265, 266, 268, 270, 272, 274, 275, 276, 278, 280, 282, 284, 285, 286, 287, 288, 304, 306, 308, 309, 320, 322, 324, 325, 326, 328, 330, 332, 333, 334, 335, 336, 338, 339, 340, 342, 344, 345, 346, 348, 350, 352, 354, 355, 356, 358, 360, 362, 363, 364, 365, 366, 368, 369, 380, 382, 384, 385, 386, 388, 390, 392, 393, 394, 395, 396, 398, 399, 404, 406, 408, 420, 422, 424, 425, 426, 428, 440, 442, 444, 445, 446, 448, 450, 452, 454, 455, 456, 458, 460, 462, 464, 465, 466, 468, 469, 480, 482, 484, 485, 486, 488, 490, 492, 494, 495, 496, 498, 504, 506, 508, 510, 512, 514, 515, 516, 518, 520, 522, 524, 525, 526, 527, 528, 540, 542, 544, 545, 546, 548, 550, 551, 552, 554, 555, 556, 558, 560, 562, 564, 565, 566, 568, 570, 572, 574, 575, 576, 578, 580, 581, 582, 584, 585, 586, 588, 604, 606, 608, 609, 620, 622, 624, 625, 626, 628, 630, 632, 633, 634, 635, 636, 638, 639, 640, 642, 644, 645, 646, 648, 649, 650, 652, 654, 655, 656, 658, 660, 662, 663, 664, 665, 666, 668, 669, 680, 682, 684, 685, 686, 688, 690, 692, 693, 694, 695, 696, 698, 699, 704, 706, 708, 720, 722, 724, 725, 726, 728, 740, 742, 744, 745, 746, 748, 750, 752, 754, 755, 756, 758, 760, 762, 764, 765, 766, 768, 770, 772, 774, 775, 776, 777, 778, 780, 782, 784, 785, 786, 788, 804, 806, 808, 810, 812, 814, 815, 816, 818, 820, 822, 824, 825, 826, 828, 840, 842, 844, 845, 846, 848, 850, 851, 852, 854, 855, 856, 858, 860, 862, 864, 865, 866, 868, 870, 872, 874, 875, 876, 878, 880, 882, 884, 885, 886, 888, 904, 906, 908, 909, 910, 912, 914, 915, 916, 918, 920, 921, 922, 924, 925, 926, 928, 930, 932, 933, 934, 935, 936, 938, 939, 940, 942, 944, 945, 946, 948, 949, 950, 951, 952, 954, 955, 956, 958, 960, 962, 963, 964, 965, 966, 968, 969, 980, 981, 982, 984, 985, 986, 988, 990, 992, 993, 994, 995, 996, 998, 999]