TopcoderArchiveVisit Topcoder
TCO31 Mar 2017
TCO17 China

Ellys8Bit

Problem statement, definition, constraints, and public examples.

Problem Statement

"Pravetz" is a well-known brand of computers in Bulgaria, as the company used to manufacture all 8-bit computers in the country during the socialism. Suddenly, after a 20-year pause from being on the market, they released a modern, 64-bit laptop.

Elly recently bought such a laptop and now her mother is confused. How can an 8-bit computer be also 64-bit!? Elly, always being pain in the assembler, decided to joke with her by coming up with the following definition: "A 64-bit 8-bit number with at most 64 bits in its binary representation, which has exactly 8 bits set. (I.e., out of the 64 bits there are exactly eight 1s.)". By this definition, the first few such numbers are 255, 383, 447, 479, etc.

Elly told her mother that, in order to be in line with the new technologies, she has to be able to calculate these numbers by heart. To her surprise, she actually started doing so. Now the girl wants to check whether her calculations are correct.

Your task is simple: given an int N, return the N-th 64-bit 8-bit number.

Definition

Class:
Ellys8Bit
Method:
getNumber
Parameters:
int
Returns:
long
Method signature:
long getNumber(int N)
(be sure your method is public)

Constraints

  • N will be between 1 and 1,000,000,000, inclusive.

Examples

  1. 1
    Returns: 255
    The first 64-bit 8-bit number is just the binary number 11111111, which is 255 in decimal.
  2. 2
    Returns: 383
    The second 64-bit 8-bit number is 101111111, which is 383 in decimal.
  3. 3
    Returns: 447
    The third 64-bit 8-bit number is 110111111, which is 447 in decimal.
  4. 1000
    Returns: 7032
    The thousandth 64-bit 8-bit number is 1101101111000, which is 7032 in decimal.
  5. 133742
    Returns: 1087088
  6. 537655880
    Returns: 1125899983585796
    Watch out for overflows!
Back to all problems