Thank you @AeryB for explaining the solution. It’s actually the same as my explanation in the other post: Seemingly incorrect analytical solution to Problem 4 of Birthday Lab, although in that post the roles of C1 and C2 are opposite to yours.
However, I’m sorry to say the solution is incorrect. Apologies
To verify my claim, assume each classroom consists of 2 people and there are only 5 days in a year instead of 365. You can use simple math to figure out the true answer is 365/625. However, the solution will produce 369/625. My post shares a simple python script about that.
The root cause is that Q = Q1 * Q2 * … Qn is incorrect. The events denoted by Q1, Q2, … Qn are not independent.
I feel that a correct analytical solution to this problem would have a complex form unfortunately.