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

Bài tập thuộc lộ trình

1 lộ trình

Đế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 2,3,5,7,11,…2,3,5,7,11,\ldots. Convert each to binary without leading zeros, then concatenate these representations into one infinite binary string. For example, 2=1022=10_2, 3=1123=11_2, 5=10125=101_2, 7=11127=111_2, so the string begins 101110111.... Given nonnegative integer NN, count the 1 characters among the first exactly NN characters. For N=0N=0 output 00.

Input

One line contains nonnegative integer NN, the prefix length.

Output

Print one integer: the number of 1 bits in the first NN characters.

Subtasks

  • Subtask 1 (20 points): 0≤N≤50000\le N\le 5000.
  • Subtask 2 (30 points): 0≤N≤10000000\le N\le 1000000.
  • Subtask 3 (50 points): 0≤N≤1500000000\le N\le 150000000.

Examples

Input

10

Output

8

Explanation

The first primes contribute 10, 11, and 101, giving 1011101 (seven bits). Append all three bits of 7=11127=111_2 to get the ten-bit prefix 1011101111. Exactly two bits are 0, so eight bits are 1; print 8.