zoukankan      html  css  js  c++  java
  • 简单的数学问题

    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.?

    输入

    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*1000000000,m < 10000) In the second line , there are ten integers represent a0 ~ a9.

    输出

    For each case, output f(k) % m in one line.

    样例输入

    10 9999
    1 1 1 1 1 1 1 1 1 1
    20 500
    1 0 1 0 1 0 1 0 1 0
    

    样例输出

    45
    104
    #include<iostream>
    using namespace std;
    int a[10];
    int f(int x)
    {
        int y;
        if(x<10)
            y=x;
        else
            y=a[0]*f(x-1)+a[1]*f(x-2)+a[2]*f(x-3)+a[3]*f(x-4)+a[4]*f(x-5)+a[5]*f(x-6)+a[6]*f(x-7)+a[7]*f(x-8)+a[8]*f(x-9)+a[9]*f(x-10);
        return y;
    
    }
    int main()
    {
         int k,m,i;
     while(cin>>k>>m)
     {
      for(i=0;i<10;i++) cin>>a[i];
     cout<<f(k)%m<<endl;
     }
     return 0;
    } 
  • 相关阅读:
    凤凰传奇
    信息孤岛
    别了,中珠
    吃苦要趁早
    触动——beyond歌词
    走出舒适区,迎接挑战
    创新永存
    信息时代
    变色龙时代——创新
    Java基本的数据类型
  • 原文地址:https://www.cnblogs.com/Lazy-Cat/p/9838463.html
Copyright © 2011-2022 走看看