×

# CPH003B-Editorial

Practice

Author: Karan Malhotra

Editorialist: Karan Malhotra

EASY

Math,Bits

# PROBLEM:

The problem basically asks to print the minimum count of positive integers , such that the sum of each (integer raised to the power 2) results in the given number N

# QUICK EXPLANATION:

The answer is the number of set bits in N

# EXPLANATION:

Every Natural Number can be represented as a sum of distinct powers of 2.Each set bit represents a distinct power.For eg - 5 (101) = 2^0 + 2^2 , the 0th and 2nd bit are set from left and the distinct powers are 1(2^0) & 4(2^2).

Many languages have built in functions to count the number of set bits.Other solutions also exist which involve manipulation of bits.Check solution for the same.

# AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.

This question is marked "community wiki".

812
accept rate: 0%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,719
×879
×77
×24
×10
×3

question asked: 25 Jan '18, 00:08

question was seen: 165 times

last updated: 25 Jan '18, 00:30