luogu#P4134. [BJOI2012] 连连看

[BJOI2012] 连连看

Problem Description

Among IQ-test problems there is often an elimination game. But this round of Lianliankan is not the visual-matching game on QQ. Our rule is: given all integers in the closed interval [a,b][a, b], if there exist two numbers xx, yy (x>yx > y) such that their square difference x2y2x^2 - y^2 is a perfect square z2z^2, and yy and zz are coprime, then you may connect xx and yy, remove them together, and gain x+yx + y points. The goal is to maximize the number of removable pairs, and subject to that, maximize the total score. Try to figure it out.

Input Format

One line with two integers, denoting aa and bb.

Output Format

Two integers: the number of pairs that can be removed, and, under that condition, the maximum total score.

1 15
2 34

Hint

Constraints:

  • For 30%30\% of the testdata, 1a,b1001 \le a, b \le 100.
  • For 100%100\% of the testdata, 1a,b10001 \le a, b \le 1000.

Translated by ChatGPT 5