编程介的小学生 2017-01-04 05:51 采纳率: 20.5%
浏览 870
已采纳

A Number from Yanghui Triangle

Description

Yanghui Triangle, as known as Pascal’s Triangle, is a number triangle with numbers arranged in staggered row such that

an, 0 = 1 (n ≥ 0)
an, n = 1 (n ≥ 0)
an, r = an − 1, r − 1 + an − 1, r (0 < r < n)

Consider a decimal number p with sequentially consists of k-digit decimal representations of the numbers in the n-th row of Yanghui Triangle where log10 an, r < k for all 0 ≤ r ≤ n. Here are some examples:

n k p
0 1 1
3 2 01030301
5 2 010510100501
The numerical value of p can be very large. Your task is to calculate p mod m for some integer m.

Input

The input consists of T test cases. The number of test cases T is given in the first line of the input file. Each test case consists of one line containing n, k, m (0 ≤ n ≤ 1 000 000, 1 ≤ k ≤ 1 000 000, 2 ≤ m ≤ 109) in order.

Output

The output should contain p mod m, one per line.

Sample Input

3
0 2 7
2 2 12345
5 2 1000000
Sample Output

1
10201
100501

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-01-11 16:44
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用