#P9006. [入门赛 #9] 神树大人挥动魔杖 (Hard Version)
[入门赛 #9] 神树大人挥动魔杖 (Hard Version)
Background
This problem has exactly the same meaning as the Easy Version, and only the constraints for are different.
Problem Description
Lord Divine Tree swings the wand and summons domesticated fairies. Each domesticated fairy has a unique -digit ID number .
Lord Divine Tree wants to divide these domesticated fairies into groups. All fairies in group satisfy that their ID number leaves remainder when taken modulo , that is, .
Lord Divine Tree wants to know how many fairies are in each group. Since the answer may be very large, you only need to output the result modulo .
Input Format
The input consists of one line with two integers, in order .
Output Format
Output one line with integers separated by spaces. The -th integer represents the number of fairies in the -th group.
3 10
90 90 90 90 90 90 90 90 90 90
Hint
For of the testdata, , .
Translated by ChatGPT 5