🔢

Prime Sums

Week 46

You are interested in number theory and want to determine if there is any relationship between the distribution of primes and prime sum of digits (the number 123 has a sum of digits = 6 - i.e. 1 + 2 + 3)

While outputting long lists of primes might help, you realise it might be easier to visually plot the data - you decide you want to create a 1000x1000 image (corresponding to numbers 1 to 1,000,000 - i.e. n = 1 is row 1, column 1 (top left), n = 2 is row 1, column 2...n = 1,000,000 is row 1000, column 1000 etc) with the following pixel colouring rules

  • red: if both the number and its sum of digits are prime
  • green: if only the number is prime
  • blue: if only the sum of digits are prime
  • black: if neither are prime

Note that colours should be pure - i.e. red is (255, 0, 0), green is (0, 255, 0) etc

It is also important your program outputs a lossless image format like .png - something like a jpg will be compressed and pixel values may not be the original ones you generated

If we look at a few values of n, we can see their colours

n = 2 (sum = 2) - both n and sum are prime, hence RED n = 17 (sum = 18) - n is prime, but sum isn't, hence GREEN n = 14 (sum = 5) - only sum is prime, hence BLUE n = 26 (sum = 8) - neither are prime, hence BLACK

Again, you should create a 1000x1000 lossless image corresponding to n = 1 to n = 1,000,000 and upload it below

Click to upload or drag & drop image here...

Hints

Hints will be released at the start of each of the following days - e.g. the start of day 3 is 48 hours after the challenge starts

Release Day Hint
2
46 2026