William Stein -- Talk for Mathematics is a long conversation: a celebration of Barry Mazur
def mult_parities(int bound, bint verbose=False):1"""2Return list v of length bound such that v[n] is 0 if n is3multiplicative even, and v[n] is 1 if n is multiplicatively odd.4Also v[0] is None.56This goes up to bound=`10^7` in about 2 seconds, but uses a lot of7memory beyond this size. On a machine with sufficient `10^8`8takes around 20 seconds. If you have about 20-30GB of RAM, you can9go to `10^9` in about 6 minutes; this is far enough to witness the10first crossover point.11"""12from sage.all import log, floor, prime_range13cdef int i, j, k, n, p, last_len, cur_ptr, last_parity, cur_parity14cdef long long m1516cdef int* v = <int*> sage_malloc(sizeof(int)*bound)17if not v: raise MemoryError1819cdef int* last = <int*> sage_malloc(sizeof(int)*bound)20if not last: raise MemoryError2122cdef int* cur = <int*> sage_malloc(sizeof(int)*bound)23if not cur: raise MemoryError2425for i in range(bound):26v[i] = -12728v[1] = 02930P = prime_range(bound)31cdef int* primes = <int*> sage_malloc(sizeof(int)*len(P))32if not primes: raise MemoryError33for i in range(len(P)):34primes[i] = P[i]35v[primes[i]] = 136last[i] = primes[i]3738cdef int len_P = len(P)39last_len = len_P40last_parity = 141cdef int loops = floor(log(bound,2))+142for k in range(loops):43cur_ptr = 044cur_parity = (last_parity+1)%245if verbose:46print "loop %s (of %s); last = %s"%(k,loops, last_len)47_sig_on48for n in range(last_len):49for j in range(len_P):50m = (<long long> last[n]) * (<long long> primes[j])51if m >= bound:52break53if v[m] == -1:54v[m] = cur_parity55cur[cur_ptr] = m56cur_ptr+=157_sig_off58last_parity = cur_parity59last_len = cur_ptr60_sig_on61for n in range(last_len):62last[n] = cur[n]63_sig_off6465ans = [v[i] for i in range(bound)]66sage_free(v)67sage_free(last)68sage_free(cur)69sage_free(primes)70ans[0] = None71return ans727374