luogu#P4882. lty loves 96!

lty loves 96!

Background

As everyone knows, ltylty really likes the two digits 9696 (if your mind went the wrong way, go face the wall right now), even more than repeating a grade (a repeating student)!

Problem Description

Because of “loving what someone loves”, ltylty also likes numbers that “contain 9696”. Here, “contain” does not mean the usual kind of contain, but must satisfy all of the following properties (all three must be met):

  • The number is an NN-digit number and has no leading zeros.
  • In this number, the digits 99 and 66 appear at least MM times in total (example: 986996986996 has 55 occurrences in total: 99 appears 33 times and 66 appears 22 times, for a total of 55).
  • There exist three consecutive digits AA, BB, CC that satisfy at least one of the following:
    • A+B+CA+B+C equals 99 or 66.
    • (A2+B2)(A^2+B^2)%CC equals 99 or 66. If CC is 00, then this condition is considered not satisfied.

Input Format

One line with two numbers NN, MM.

Output Format

One number, representing the count of such numbers.

3 1
16

Hint

For 10%10\% of the testdata, N6N \le 6.

For 40%40\% of the testdata, N18N \le 18.

For 100%100\% of the testdata, N50N \le 50, 0MN0 \le M \le N.

Translated by ChatGPT 5