2262: Crime

内存限制:512 MB 时间限制:30.000 S
评测方式:文本比较 命题人:
提交:13 解决:1

题目描述

You kill a person and will be executed by shooting tomorrow,but you have a program contest to do today,after several hours' hard work,you solved all problems except this one.You died with the pity that didn't solved it.But now you have second chance.
Count the number of permutation of number 1 to n that every adjacent number are coprime.To avoid large number,output the result mod a number M.

输入

The first line contains integer T(1<=T<=5).Denoting the number of the test cases.
Then T lines follows,each line contains two integers n,M (1<=n<=28, 1<=M<=30000).
The n for each test cases will not be the same.

输出

For each test cases,print the answer in a line.

样例输入 复制

5
1 10000
2 10000
3 10000
4 10000
5 10000

样例输出 复制

1
2
6
12
72

来源/分类