This is very simple question

A. Lloyd Flanagan alloydflanagan at comcast.net
Wed Apr 21 18:06:23 EDT 2004


ekoome at yahoo.com (Eric) wrote in message news:<b0457a31.0404210754.2a34b6be at posting.google.com>...
> I would want to obtain a list of factors (multiples of 2) given a
> prime number in python.
> 
> For example 13=[8,4,1], 5=[4,1], 7=[4,2,1], 15=[8,4,2,1]
> 
> I would appreciate a fuction which would do this.
> 
> Eric

Minor quibble: you don't mean factors.  The only factors of a prime
number are the number itself and one; that's the definition of a prime
number.

Now, do you want a list of all powers of 2 less than a prime number,
OR do you want a list of powers of 2 such that the sum of the numbers
is the given prime number?  For Mersienne primes, which are of the
form (2**n-1) the answer is the same either way.  All your examples
are Mersienne primes.
But look at 11:
11 = 8 + 2 + 1, not 8 + 4 + 2 + 1

Of course, any odd number can be expressed as 2 + 2 + ... + 1, so what
you would really want is the shortest list of powers of 2 that add up
to the prime.



More information about the Python-list mailing list