wu :: forums
« wu :: forums - count  numbers that have prime # of bits set »

Welcome, Guest. Please Login or Register.
Mar 16th, 2025, 3:39pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Eigenray, william wu, Icarus, towr, Grimbal, SMQ, ThudnBlunder)
   count  numbers that have prime # of bits set
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: count  numbers that have prime # of bits set  (Read 481 times)
inexorable
Full Member
***





   


Posts: 211
count  numbers that have prime # of bits set  
« on: Oct 24th, 2007, 4:32pm »
Quote Quote Modify Modify

consider a function P(x) where:
 
  P(x) returns:
    true if the number of 1 bits set in the
 binary representation of x is prime,
 
    false otherwise.
 
For example, P(239) returns true, while P(51) returns false.
 
Next, consider the following function prime_bits:
 
  uint64_t prime_bits(uint64_t a, uint64_t b);
 
A call to prime_bits(a, b) returns the number of values between a and b inclusive for which P(x) is true. For example, prime_bits(4, 10) returns 5, while prime_bits(137, 31415926535897) returns 7753256197126.
 
How do you implement prime_bits(a,b) such that its running time is faster than O(n) where n=b-a ?
« Last Edit: Oct 24th, 2007, 5:12pm by inexorable » IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: count  numbers that have prime # of bits  
« Reply #1 on: Oct 25th, 2007, 2:29am »
Quote Quote Modify Modify

I'd look up the previous thread on the subject before implementing it..
In any case, you'd use combinatorics.
« Last Edit: Oct 25th, 2007, 2:35am by towr » IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board