oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

binarycoins Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

binarycoins.html

Problem Description

Si the JieJie has too much money. Today, he is feeling rich and carried $B as pocket money to school.

As he is too rich, he wants to feel poorer by converting his money into as few notes as possible and needs your help.

In the Jiejie world, notes comes in denomations of powers of 2. (Eg: $1, $2, $4, $8, $16, $32 .. etc)

Input

A single integer, B, denoting how much money Si the JieJie brought to school today.

It is guaranteed that B will fit into a 64-bit unsigned integer.

Output

A single integer, denoting the minimum number of notes required to express $B in notes.

Sample Input

19

Sample Output

3

Explanation for Sample Testcase

19 can be expressed as 16 + 2 + 1 for a minimum of 3 notes.

Tags

Greedy, Number Theory

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
11001001s32MBAverage

Judge Compile Command

g++-8 ans.cpp -o binarycoins -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.