Official
B - 会員証の番号 / Membership Card Number Editorial by admin
swe-2-highThe program repeatedly adds the last decimal digit, \(N \bmod 10\), to \(s\), then removes that digit by integer division by \(10\). After each iteration, \(s\) equals the digit sum of the removed suffix, so when \(N\) reaches \(0\), \(s\) is the digit sum of the original number. There are \(O(\log N)\) digits, each processed in constant time. Only scalar variables and the scalar output are stored. Time: \(O(\log N)\); space: \(O(1)\).