def co_concat_prime(x, y): if (x,y) not in known: if (x + y) % 3 ==0: known[(x,y)] = False return False mx = 10 ** intlen(x) my = 10 ** intlen(y) c1 = mx*y + x c2 = my*x + y if c1 < c2: known[(x,y)] = lazy_is_prime(c1) and lazy_is_prime(c2) else: known[(x,y)] = lazy_is_prime(c2) and lazy_is_prime(c1) return known[(x,y)]
def p058(): spiral_count = 0 prime_count = 0 for side_length, spirals in grouped_spirals(): spiral_count += len(spirals) prime_count += sum((1 for spiral in spirals if lazy_is_prime(spiral))) if side_length > 2 and prime_count * 10 < spiral_count: return side_length