编程介的小学生 2019-06-11 10:59 采纳率: 20.5%
浏览 129

最小堆的表示和生成的一个算法,是怎么采用C语言的程序编写过程的代码设计实现的呢?

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
    • ¥15 扩散模型sd.webui使用时报错“Nonetype”
    • ¥15 stm32流水灯+呼吸灯+外部中断按键
    • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
    • ¥15 NX MCD仿真与博途通讯不了啥情况
    • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
    • ¥15 gradio的web端页面格式不对的问题
    • ¥15 求大家看看Nonce如何配置
    • ¥15 Matlab怎么求解含参的二重积分?
    • ¥15 苹果手机突然连不上wifi了?