F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Minimum Heap

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 320    Accepted Submission(s): 147


Problem Description
Alex is curious about data structures. He is working on binary trees recently and particularly interested in complete binary trees.


A complete binary tree satisfies that all levels of the tree, except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not complete, the nodes of that level are filled from left to right.
Alex defines his own complete binary tree: each node has a weight, while father's is always less than or equal to its sons'. He names this complete binary tree as minimum heap.

Now he wants to know: With N nodes weighted from 1 to N (each appears once), how many heaps can be created. The answer (represented by Q) may be very large, so please output a number P while P = Q mod M.

 

Input
The input consists of several test cases. The first line contains a number T, indicating the number of test cases. Each test case is on a single line, and it consists the number N and M.
Technical Specification
1. 1 ¡Ü T ¡Ü 10
2. 1 ¡Ü N ¡Ü 1000
3. 2 ¡Ü M ¡Ü 1000,000,000

 

Output
For each test case, output the number P on a single line.
 

Sample Input
2 1 9973 100 9973
 

Sample Output
1 174
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-26 15:48:26, Gzip enabled