Блог пользователя I_LOVE_ROMANIA

Автор I_LOVE_ROMANIA, история, 6 лет назад, По-английски

Hey guys! My professor proposed me to solve this problme. Given a number p <= 10^7, print the sum of the digits of 2^p. For exemple, 2^4 = 16 so we'll print 7. How can I do this properly? I first tried to use in a way or in another, the little theorem of fermat but it made no sense here.

  • Проголосовать: нравится
  • +26
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +62 Проголосовать: не нравится

Well since $$$2^p$$$ will have less than $$$10^7$$$ digits you can compute $$$2^p$$$ by using FFT with complexity $$$Nlog^2N$$$. Then you simply find the sum of the digits.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +155 Проголосовать: не нравится

Tell your prof that in base 2 the sum of the digits is just 1

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Your answer seems so straight forward that I spent few minutes thinking how to compute sum of digits mod 2, just to realize that you mean't sum of digits when the number is itself in base 2 :facepalm:

    Is it any easy way to compute sum of digits mod 2?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

interesting, i like your prof

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -19 Проголосовать: не нравится

you can do the computation in strings then finally add the result