Sum Squared Digits Function

From programming_contest
Revision as of 22:42, 27 December 2017 by imported>Kmk21 (Created page with "This problem asks you to convert an input number to a given base and then compute the sum of the squares of the digits. The only challenge here is to know how to convert base...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This problem asks you to convert an input number to a given base and then compute the sum of the squares of the digits.

The only challenge here is to know how to convert bases, and it's not even that hard, since the answer does not need to be constructive...we only need the sum.

  1. while number is not 0
  2. ans += (number % base)^2
  3. ans /= base