PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000070. Đếm bit 1 trong dãy nhị phân nguyên tố (Binary Sequence of Prime Number)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm bit 1 trong dãy nhị phân nguyên tố (Binary Sequence of Prime Number)
Binary Sequence of Prime Number
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Take increasing primes . Convert each to binary without leading zeros, then concatenate these representations into one infinite binary string. For example, , , , , so the string begins 101110111.... Given nonnegative integer , count the 1 characters among the first exactly characters. For output .
Input
One line contains nonnegative integer , the prefix length.
Output
Print one integer: the number of 1 bits in the first characters.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
10
Output
8
Explanation
The first primes contribute 10, 11, and 101, giving 1011101 (seven bits). Append all three bits of to get the ten-bit prefix 1011101111. Exactly two bits are 0, so eight bits are 1; print 8.