There are n people falling in love. Everybody has a unique people he/she loves, and somebody love themselves. But they have a secret agreement: no two people love the same one. To satisfy such a relationship between n people, we call it a

, denoted by

. Obviously, there are n! different

for n people. And a

can be presented as a permutation. For example, if n = 3,

means the first people loves the third people, the second people loves the first people, the third people loves the second people.
if A loves B, and B loves C, and C loves A, then we call the relationship between these 3 people

. and so on, we can easily define

for each integer k. Extraordinary, if A loves B and B loves A, we call them

. If A loves himself, we call it

.
Apollo said proudly to Avery: If I konw "how many

are there in this relationship" for each k, Then I can easily tell you how many relationship combinations might be legal for these n people.
But Avery said: No, It's not enough. Let's use
)
to denote the number of

of n people, which can form

,

, ...,and

. If one relationship

of n people can form

,

, ...,

, and
)
is divisible by my favourite number P, then I will feel the relationship

is disgusting. I will tell you my favourite number P, and could you calculate how many relationships are

disgusting between these n people? I know this might be too difficult to you, so you can just tell me how many

of

are

disgusting.

: for relationships

and

, if

will let there be

k-love polygons for each

,

will let there be

k-love polygons for each

, and there exist at least one i, such that

, then we call love relationships

and

are

.
Apollo could not handle this task very well. Could you help him?