luogu#P9231. [蓝桥杯 2023 省 A] 平方差

[蓝桥杯 2023 省 A] 平方差

Problem Description

Given L,RL, R, ask how many integers xx with LxRL \leq x \leq R satisfy that there exist integers y,zy, z such that x=y2z2x = y^2 - z^2.

Input Format

Input one line containing two integers L,RL, R, separated by one space.

Output Format

Output one line containing one integer: the number of xx that satisfy the condition in the problem statement.

1 5
4

Hint

Sample Explanation

  • 1=12021 = 1^2 - 0^2
  • 3=22123 = 2^2 - 1^2
  • 4=22024 = 2^2 - 0^2
  • 5=32225 = 3^2 - 2^2

Constraints

For 40%40\% of the testdata, L,R5000L, R \leq 5000.

For all testdata, 1LR1091 \leq L \leq R \leq 10^9.

The 14th Lanqiao Cup Software Competition, Provincial Contest, C/C++ Undergraduate Group A, Problem C.

Translated by ChatGPT 5