#P15434. [蓝桥杯 2025 国 Python B] 三角形构造

[蓝桥杯 2025 国 Python B] 三角形构造

Problem Description

Xiao Lan is drawing triangles. He first fixes the length of one side of the triangle as xx. You need to find how many positive integers yy satisfy all of the following conditions:

  • 1yx1 \le y \le x;
  • The three numbers xx, yy, and xyx | y can form the side lengths of a non-degenerate triangle.

Here, xyx | y denotes the bitwise OR result of xx and yy in binary.

Note: A triangle is non-degenerate, which means its three side lengths a,b,ca, b, c must all be positive and satisfy the triangle inequalities: a+b>ca + b > c, a+c>ba + c > b, and b+c>ab + c > a.

If any inequality becomes an equality (for example, a+b=ca + b = c), then the triangle is degenerate (the three points are collinear).

Input Format

Input one line containing a positive integer xx.

Output Format

Output one line containing an integer representing the answer.

10
7

Hint

Sample Explanation

Valid values of yy are: 2,3,6,7,8,9,102, 3, 6, 7, 8, 9, 10.

Constraints

For 30%30\% of the testdata, 1x1031 \le x \le 10^3.

For all testdata, 1x10161 \le x \le 10^{16}.

Translated by ChatGPT 5