Submit | All submissions | Best solutions | Back to list |
PT07D - Let us count 1 2 3 |
Given two integer n, p. 4 kinds of query is needed to solve:
- Counting the number of labeled unrooted trees with n nodes.
- Counting the number of labeled rooted trees with n nodes.
- Counting the number of unlabeled rooted trees with n nodes.
- Counting the number of unlabeled unrooted trees with n nodes.
Input
Each line contains three integers k, n, p. k denotes which kind of query this
case is.
For Kind 1 or Kind 2 query, 1 <= n <= 109.
For Kind 3 or Kind 4 query, 1 <= n <= 103 and n <= p.
For all queries, 2 <= p <= 104 and p is a prime.
Output
For each query, output a line which contains only one integer.
Example
Input: 1 2 2 2 2 3 3 2 5 4 2 3 Output: 1 2 1 1
Added by: | Thanh-Vy Hua |
Date: | 2007-04-07 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | ADA95 ASM32 BASH BF C CSHARP CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN HASK ICON ICK JAVA LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST TEXT WHITESPACE |
Resource: | Co-author Amber |