0
$\begingroup$

Let N be the sum of all numbers from 1 to 1023 except the five prime numbers 2, 3, 11, 17 , 31, all numbers are represented by two bytes, what is the value of least significant byte? My approach is sum of N natural number up to 1023 is $\frac{n(n+1)}{2}=\frac{2^{10} (2^{10}-1)}{2}$ which, once I subtract 64 from the given number, gives $ (2^{19}-2^9-2^6)$ which gives me 01000000 as the value of least significant byte, but the answer is 11000000. I think I am doing something wrong. For not having any doubts I am giving the image of original question.

enter image description here

$\endgroup$
  • $\begingroup$ Hint: $\sum_{n=1}^{1023} n = \frac{(1023)(1024)}{2} = 1023 \cdot 512$, and because $512$ is divisible by $256 (= 100000000_2)$, the last $8$ bits of the sum of all numbers from $1$ to $1023$ are all $0$. Now, subtract $64 (= 1000000_2)$, which is the sum of the five prime numbers. $\endgroup$ – 2012ssohn Dec 10 '16 at 6:29
  • $\begingroup$ Am I not doing the same thing, I mean where I am doing wrong? $\endgroup$ – Userhanu Dec 10 '16 at 6:36
  • $\begingroup$ Either you added $1000000_2$ or thought you were subtracting it from $...10000000_2$ when you were supposed to subtract it from $...00000000_2$. Those are my guesses anyway. $\endgroup$ – 2012ssohn Dec 10 '16 at 18:05
1
$\begingroup$

This is another way of saying , what will be the remainder when $N$ is divided by $2^8=256$?

Here $$N = \frac{1023\times 1024}{2} - (2+3+11+17+31)$$ $$= 1023\times 512 - 64$$ $$= 1022\times 512 + (512-64)$$ $$ = 1022\times 512 + 448$$

Now $448\pmod{256} =192 = 11000000_{2}.$

$\endgroup$
  • $\begingroup$ I completely agree, but please can you tell me where I was wrong in my approach. $\endgroup$ – Userhanu Dec 10 '16 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.