zoukankan      html  css  js  c++  java
  • hdoj 1757 A Simple Math Problem

    A Simple Math Problem

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

    Problem Description
    Lele now is thinking about a simple function f(x).

    If x < 10 f(x) = x.
    If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10);
    And ai(0<=i<=9) can only be 0 or 1 .

    Now, I will give a0 ~ a9 and two positive integers k and m ,and could you help Lele to caculate f(k)%m.
     
    Input
    The problem contains mutiple test cases.Please process to the end of file.
    In each case, there will be two lines.
    In the first line , there are two positive integers k and m. ( k<2*10^9 , m < 10^5 )
    In the second line , there are ten integers represent a0 ~ a9.
     
    Output
    For each case, output f(k) % m in one line.
     
    Sample Input
    10 9999 1 1 1 1 1 1 1 1 1 1 20 500 1 0 1 0 1 0 1 0 1 0
     
    Sample Output
    45 104
     
    Author
    linle
     思路:裸的矩阵快速幂,首先要构造矩阵
    [fn]         [XXX]        [fn-1]
    [fn-1]   = [XXX]  *    [fn-2]
    [fn-2]      [XXX]        [fn-3]
    ……            ……            ……    
    思考一下就可以得到
    [fn]         [a0 a1 a2]        [fn-1]
    [fn-1]   = [1  0   0]  *    [fn-2]
    [fn-2]      [ 0  1  0 ]        [fn-3]
    ……            ……            ……    
  • 相关阅读:
    C++ Base64 编码 解码
    C语言 线性表 链式表结构 实现
    C语言 线性表 顺序表结构 实现
    Python基于共现提取《釜山行》人物关系
    SciPy
    操作 numpy 数组的常用函数
    Numpy
    Python 科学计算-介绍
    使用Python定制词云
    事件驱动-协程实现爬虫
  • 原文地址:https://www.cnblogs.com/cshg/p/5918339.html
Copyright © 2011-2022 走看看