Ellys8Bit
TCO17 China · 2017-03-31 · by espr1t
TCO17 China · 2017-03-31 · by espr1t · Simple Math
Problem Statement
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 anint N, return the N-th 64-bit 8-bit number.
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
Constraints
- N will be between 1 and 1,000,000,000, inclusive.
Examples
0)
1 Returns: 255
The first 64-bit 8-bit number is just the binary number 11111111, which is 255 in decimal.
1)
2 Returns: 383
The second 64-bit 8-bit number is 101111111, which is 383 in decimal.
2)
3 Returns: 447
The third 64-bit 8-bit number is 110111111, which is 447 in decimal.
3)
1000 Returns: 7032
The thousandth 64-bit 8-bit number is 1101101111000, which is 7032 in decimal.
4)
133742 Returns: 1087088
5)
537655880 Returns: 1125899983585796
Watch out for overflows!
Submissions are judged against all 102 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class Ellys8Bit with a public method long long getNumber(int N) · 102 test cases · 2 s / 256 MB per case