You are not logged in. Please login at www.codechef.com to post your questions!

×

CPH003B-Editorial

PROBLEM LINK:

Practice

Author: Karan Malhotra

Tester Dushyant Singh , Deepansh Parmani

Editorialist: Karan Malhotra

DIFFICULTY:

EASY

PREREQUISITES:

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".

asked 25 Jan '18, 00:08

kmalhotra30's gravatar image

4★kmalhotra30
812
accept rate: 0%

edited 25 Jan '18, 00:30

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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