我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

Counting Binary Trees 树的算法编程

Problem Description
There are 5 distinct binary trees of 3 nodes:

Let T(n) be the number of distinct non-empty binary trees of no more than n nodes, your task is to calculate T(n) mod m.

Input
The input contains at most 10 test cases. Each case contains two integers n and m (1 <= n <= 100,000, 1 <= m <= 109) on a single line. The input ends with n = m = 0.

Output
For each test case, print T(n) mod m.

Sample Input
3 100
4 10
0 0

Sample Output
8
2

近期文章

  • List Operations 的设计的问题
  • Windows 窗口的问题
  • Strange Clock 时钟问题
  • Selecting Frames 框架的问题
  • 海选女主角 的算法问题
  • 插入到序列中,并使新的序列仍然有序
  • Java语言比较两个字符串所有的不同的字符,输出
  • 页面播放MP4&MP3都没有声音
  • 请教一种vue项目的语法
  • Python中如何将时间格式转为字符串?
  • Python中如何将时间格式转为字符串?
  • 未安装任何音频输出设备
  • 运行错误,什么原因?求大佬解答!
  • 求推荐MPNet软件,是什么软件?
  • 日志提示Context initialization failed,查了很多未果,求大神指导
  • thanno编译过程中遇到在错误
  • 为什么不能继续录入成绩
  • thanno编译过程中遇到在错误
  • ssm后台找不到url的handler?
  • Class.forName() 报错ClassNotFound

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华