<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://michaelnielsen.org/polymath/index.php?action=history&amp;feed=atom&amp;title=Search_for_completely_multiplicative_sequences</id>
	<title>Search for completely multiplicative sequences - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://michaelnielsen.org/polymath/index.php?action=history&amp;feed=atom&amp;title=Search_for_completely_multiplicative_sequences"/>
	<link rel="alternate" type="text/html" href="https://michaelnielsen.org/polymath/index.php?title=Search_for_completely_multiplicative_sequences&amp;action=history"/>
	<updated>2026-05-08T02:59:28Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://michaelnielsen.org/polymath/index.php?title=Search_for_completely_multiplicative_sequences&amp;diff=2688&amp;oldid=prev</id>
		<title>Alec: New page: This is a simple Python script to search for all completely multiplicative sequences of successively greater length. At the top of the script, &#039;N&#039; is the limit of the search, and &#039;limit&#039; i...</title>
		<link rel="alternate" type="text/html" href="https://michaelnielsen.org/polymath/index.php?title=Search_for_completely_multiplicative_sequences&amp;diff=2688&amp;oldid=prev"/>
		<updated>2010-01-13T09:38:05Z</updated>

		<summary type="html">&lt;p&gt;New page: This is a simple Python script to search for all completely multiplicative sequences of successively greater length. At the top of the script, &amp;#039;N&amp;#039; is the limit of the search, and &amp;#039;limit&amp;#039; i...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This is a simple Python script to search for all completely multiplicative sequences of successively greater length. At the top of the script, &amp;#039;N&amp;#039; is the limit of the search, and &amp;#039;limit&amp;#039; is the constraint on the sums. It prints out lists of primes where the sequence is &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
N = 300&lt;br /&gt;
limit = 2&lt;br /&gt;
&lt;br /&gt;
# fisrt use Eratosthenes to find the primes up to N&lt;br /&gt;
# is_prime[n] = true iff n is prime&lt;br /&gt;
is_prime = [None, False] + [True]*(N-1)&lt;br /&gt;
p = 2&lt;br /&gt;
ok = True&lt;br /&gt;
while ok:&lt;br /&gt;
  for i in range(2*p, N+1, p):&lt;br /&gt;
    is_prime[i] = False&lt;br /&gt;
  ok = (True in is_prime[p+1:])&lt;br /&gt;
  if ok:&lt;br /&gt;
    p = p+1 + is_prime[p+1:].index(True)&lt;br /&gt;
&lt;br /&gt;
# make list of primes&lt;br /&gt;
primes = []&lt;br /&gt;
for i in range(1, N+1):&lt;br /&gt;
  if is_prime[i]:&lt;br /&gt;
    primes.append(i)&lt;br /&gt;
n_primes = len(primes)&lt;br /&gt;
&lt;br /&gt;
# make list a[1..N] where a[n] is a dict with primes as keys and a[n][p] = True&lt;br /&gt;
# iff p|n an odd number of times&lt;br /&gt;
a = [None]&lt;br /&gt;
for n in range(1,N+1):&lt;br /&gt;
  fact = {}&lt;br /&gt;
  k = n&lt;br /&gt;
  for p in primes:&lt;br /&gt;
    v = False&lt;br /&gt;
    while k % p == 0:&lt;br /&gt;
      v = not v&lt;br /&gt;
      k /= p&lt;br /&gt;
    fact[p] = v&lt;br /&gt;
  a.append(fact)&lt;br /&gt;
&lt;br /&gt;
n_seqs = [1]&lt;br /&gt;
xx = [[[False]*n_primes, 1]] # 0th item = specification of primes for which x[p]=-1, 1st item = partial sum&lt;br /&gt;
c = 1&lt;br /&gt;
n = 2&lt;br /&gt;
while (n&amp;lt;=N) &amp;amp; (c&amp;gt;0):&lt;br /&gt;
  print &amp;quot;first sequence:&amp;quot;, [primes[i] for i in range(n_primes) if xx[0][0][i]]&lt;br /&gt;
  new_xs = []&lt;br /&gt;
  if is_prime[n]:&lt;br /&gt;
    # ... fork&lt;br /&gt;
    i = primes.index(n)&lt;br /&gt;
    for x in xx:&lt;br /&gt;
      seq = x[0]&lt;br /&gt;
      tot = x[1]&lt;br /&gt;
      new_seq = list(seq)&lt;br /&gt;
      new_seq[i] = True&lt;br /&gt;
      new_xs.append([new_seq, tot-1])&lt;br /&gt;
      x[1] = tot+1&lt;br /&gt;
  else:&lt;br /&gt;
    # ... factorise&lt;br /&gt;
    fact = a[n]&lt;br /&gt;
    for x in xx:&lt;br /&gt;
      seq = x[0]&lt;br /&gt;
      v = 1&lt;br /&gt;
      for i in range(n_primes):&lt;br /&gt;
        if fact[primes[i]] &amp;amp; seq[i]:&lt;br /&gt;
          v = -v&lt;br /&gt;
      x[1] += v&lt;br /&gt;
  # remove sequences with bad sums&lt;br /&gt;
  xx = [x for x in xx+new_xs if abs(x[1])&amp;lt;=limit]&lt;br /&gt;
  c = len(xx)&lt;br /&gt;
  n_seqs.append(c)&lt;br /&gt;
  print &amp;quot;\nn =&amp;quot;, n&lt;br /&gt;
  print &amp;quot;number of sequences =&amp;quot;, c&lt;br /&gt;
  n += 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Alec</name></author>
	</entry>
</feed>