A Simple Math Problem

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

0

1个回答

 import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        printResult();
    }

    public static void printResult() {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextInt()) {
            int k = scanner.nextInt();
            int m = scanner.nextInt();
            int[] arr = new int[10];
            for(int i = 0; i < 10; i++)
                arr[i] = scanner.nextInt();
            System.out.println(getResult(arr, k) % m);
        }

    }

    public static int getResult(int[] a, int x) {
        if(x < 10)
            return x;
        ArrayList<Integer> list = new ArrayList<>();
        int result = 0;
        for(int i = 0; i <= x; i++) {
            if(i < 10)
                result = i;
            else {
                result = a[0]*list.get(i-1)+a[1]*list.get(i-2)+a[2]*list.get(i-3)+a[3]*list.get(i-4)+a[4]*list.get(i-5) +
                        a[5]*list.get(i-6)+a[6]*list.get(i-7)+a[7]*list.get(i-8)+a[8]*list.get(i-9)+a[9]*list.get(i-10);
            }
            list.add(result);
        }
        return list.get(x);
    }
}

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
A Simple Math Problem
Problem DescriptionnLele now is thinking about a simple function f(x).nnIf x < 10 f(x) = x.nIf x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10);nAnd ai(0<=i<=9) can only be 0 or 1 .nnNow, I will give a0 ~ a9 and two positive integers k and m ,and could you help Lele to caculate f(k)%m.n nnInputnThe problem contains mutiple test cases.Please process to the end of file.nIn each case, there will be two lines.nIn the first line , there are two positive integers k and m. ( k<2*10^9 , m < 10^5 )nIn the second line , there are ten integers represent a0 ~ a9.n nnOutputnFor each case, output f(k) % m in one line.n nnSample Inputn10 9999n1 1 1 1 1 1 1 1 1 1n20 500n1 0 1 0 1 0 1 0 1 0n nnSample Outputn45n104n
A Simple Math Problem(矩阵快速幂)
Lele now is thinking about a simple function f(x).nIf x &amp;lt; 10 f(x) = x.nIf x &amp;gt;= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10);nAnd ai(0&amp;lt;=i&amp;lt;=9) can only be 0 or 1 .nN...
A Simple Math Problem【矩阵快速幂】
A Simple Math ProblemTime Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5673    Accepted Submission(s): 3470Problem DescriptionLele now is thinking...
HDU 6441 Find Integer(费马大定理)
Find IntegernnTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)nTotal Submission(s): 1199    Accepted Submission(s): 340Special Judgen nnProblem Descriptionnnpeople i...
A simple math problem【打表找规律】
“玲珑杯”ACM比赛 Round #19 n题意: n输入n值,根据题目公式,算出10的第An项次幂; n思路: n根据这两天写题发现,打表找规律进而推公式,是一个不错的好方法,这个题的规律打表就会发现,详看代码中的枚举;#include<cstdio>n#include<cstring>n#include<algorithm>n#include<cmath>n#include<queue>n#in
A Simple Math Problem(矩阵快速幂(模板))
【题目来源】:https://vjudge.net/problem/HDU-1757 n【题意】 n求解数k对应的f(k)%m,关系式如题面所示。 n【思路】 n既然给出了递推式,又因为k的取值上限相当大,所以使用矩阵快速幂来实现f(k)的求解。这个时候就可以用到系数矩阵来表示题面给出的关系式。 n什么是系数矩阵呢?举个例子(从麻省理工学院线性代数视频上看的): n假如有三个未知数:x,y,z;
HDU - 1757 A Simple Math Problem​​​​​​​ 【矩阵快速幂】
HDU - 1757 A Simple Math Problemnnn A Simple Math Problemn Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)n Total Submission(s): 6589    Accepted Submission(s...
【A Simple Math Problem】【HDU - 1757 】(矩阵快速幂)
题目:nnLele now is thinking about a simple function f(x). nIf x &amp;lt; 10 f(x) = x. nIf x &amp;gt;= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10); nAnd ai(0&amp;lt;=i&amp;lt;=9) can only be 0 ...
A+B Problem II——大数定理
A+B Problem IIrn时间限制:3000 ms  |  内存限制:65535 KBrn难度:3rnrnrn描述 rnI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.rnA,B must be positive.rnrn输入
1757 A Simple Math Problem(矩阵快速幂入门)
A Simple Math ProblemnTime Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)nTotal Submission(s): 5025    Accepted Submission(s): 3037nnnnProblem DescriptionnnLele
【已解决】使用pip安装包提示TLS证书错误解决办法
最近有不少同学在使用pip安装python包的时候,经常会出现以下类似的错误:nnnnCould not fetch URL https://pypi.python.org/simple/pytest-xdist/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tls...
A Simple Problem with Integers(树状数组,改段求段)
                               A Simple Problem with IntegersnnYou have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number t...
uva 1380 - A Scheduling Problem 一个调度问题 好难的动态规划
想不出来啊!!!,紫书上写的很清楚。nnn1.利用题目给出的图论定理,先不考虑无向边,假如图中有向链的最大长度为K,那么答案为K+1或K+2(注意是K链的长度,答案是链包含点的个数)。nnn2.考虑答案是否能为K+1,否则为K+2,即考虑给无向边定向,定向之后能否使最长链不超过K?nnn进行动态规划来考虑:n对于每一个结点nin[x] 表示: 在定向后最长链不超过K的前提下,
Python安装及Scrapy配置中遇到的BUG及解决方案
将两个版本的python安装目录中的如下文件分别重命名:npython.exe和pythonw.exe分别重命名为python2(或3).exe和pythonw2(或3).exennnn将两个版本的的安装路径分别加入环境变量中的path:n【D:\python2713\py2\Scripts】和【D:\python2713\py2】nnnnnn配置成功之后cmd运行效果如下
2019年湘潭大学程序设计竞赛(重现赛)C:Math Problem(打表找规律)
【题面】nn链接:https://ac.nowcoder.com/acm/contest/893/Cn来源:牛客网nn时间限制:C/C++ 1秒,其他语言2秒n空间限制:C/C++ 32768K,其他语言65536Kn64bit IO Format: %lldnn题目描述nn已知整数a,除192的余数是1。求区间[L,R]之间满足条件的a的累加和是多少?nn输入描述:nnn第一行是一个整数T(1≤...
关于使用pip时,遇到的问题
问题描述:n当我使用pip install +需要的安装包时,其会报如下错误:n InsecurePlatformWarningnCould not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.or...
Problem A: 类的初体验
HomernWeb BoardrnProblemSetrnStandingrnStatusrnStatisticsrnrnrnrnrnrnrnProblem A: 类的初体验rnTime Limit: 1 Sec  Memory Limit: rn128 MBrnSubmit: 723  Solved: 661rn[Submit][Status][Webrn Board]rnDescription
天梯赛L1-014简单题——java
L1-014 简单题(5 分)nn这次真的没骗你 —— 这道超级简单的题目没有任何输入。nn你只需要在一行中输出事实:“This is a simple problem.”就可以了。nn代码:nnnnpublic class L1_014 {n public static void main(String args[]) {n System.out.println(&quot;“This is a simp...
POJ 3468 A Simple Problem with Integers(线段树,区间更新,区间查询,lazy标记)
A Simple Problem with IntegersnTime Limit: 5000MS Memory Limit: 131072KnTotal Submissions: 152160 Accepted: 47174nCase Time Limit: 2000MSnDescriptionnYou have N integers, A1, A2, … , AN. You need to...
线段树 || 树状数组解决区间更新区间查询问题----poj 3468 百练 3439 A Simple Problem with Integers
树状数组实现区间更新区间查询:n要实现区间更新区间查询操作必须像这篇文章里面一样,引入一个数组a[],区间加就只要在这个数组区间左加增量,区间右后一个位置减增量。下面公式org[]表示变化之前的数据。nsum(x) = org[1] +... ...+ org[x] + (a[1]) + (a[1]+a[2]) + ... ...+ (a[1]+... ...a[x])n            =...
A simple Problem of C++
[code=C/C++]for(int i=0;i0 && a[i]==a[i-1])rn continue;rn cout<
A simple problem!?
<%@ reference page="xxx.aspx"%>rn在一个aspx页面开头加上这一句的作用是什么?
A Simple Problem
Problem DescriptionnFor a given positive integer n, please find the smallest positive integer x that we can find an integer y such that y^2 = n +x^2.n nnInputnThe first line is an integer T, which is the the number of cases.nThen T line followed each containing an integer n (1<=n <= 10^9).n nnOutputnFor each integer n, please print output the x in a single line, if x does not exit , print -1 instead.n nnSample Inputn2n2n3n nnSample Outputn-1n1
A Simple Problem with Integers
DescriptionnnYou have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval.nnInputnnThe first line contains two numbers N and Q. 1 ≤ N,Q ≤ 100000.nThe second line contains N numbers, the initial values of A1, A2, ... , AN. -1000000000 ≤ Ai ≤ 1000000000.nEach of the next Q lines represents an operation.n"C a b c" means adding c to each of Aa, Aa+1, ... , Ab. -10000 ≤ c ≤ 10000.n"Q a b" means querying the sum of Aa, Aa+1, ... , Ab.nnOutputnnYou need to answer all Q commands in order. One answer in a line.nnSample Inputnn10 5n1 2 3 4 5 6 7 8 9 10nQ 4 4nQ 1 10nQ 2 4nC 3 6 3nQ 2 4nSample Outputnn4n55n9n15
Problem A: 好多书啊!
Problem A: 好多书啊!rnTime Limit: 1 Sec  Memory Limit: 128 MBrnSubmit: 373  Solved: 255rn[Submit][Status][Webrn Board]rnDescriptionrnrn每次开学,都要买好多教材,好多好多的money就这样不见了,见了,了,......rn我们以教材款的总额来表示我们的伤心度。所以!我们需要
A. A simple Problem(2019武大校赛现场赛)(吉比特杯第二届湖北省程序设计大赛) 解题报告 Apare_xzc
A. A simple Problem(2019武大校赛现场赛)(吉比特杯第二届湖北省程序设计大赛) 解题报告nxzc 2019/4/15nn题意:n求下列式子,其中有K个bn((((a)^b)^b)^b...)^b % pnnn数据范围:n  1&lt;=a,b,p&lt;=1E7n  1&lt;=k&lt;=1E18nn输入:n  第一行一个T,代表T组数据n  下面有T行,每行4个数,a,...
a math problem
请问如何求一个矩阵的特征值和特征向量?rn立即给分!!!!!!!!!!!!!!!
a simple stone game--k倍动态规划减法游戏
a simple stone gamernTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)rnTotal Submission(s): 298    Accepted Submission(s): 202rnrnrnrnProblem DescriptionrnrnAfter he
2019中山大学程序设计竞赛(重现赛) 1002Triangle
TrianglennTime Limit: 4000/2000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)nTotal Submission(s): 7179Accepted Submission(s): 856nnnProblem DescriptionnnAfter Xiaoteng took a mat...
2011百校联动“菜鸟杯”程序设计公开赛_A A Simple Problem
A Simple ProblemTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 5749    Accepted Submission(s): 1516Problem DescriptionFor a given positive inte...
A1078 Hashing (25 分)(给定序列哈希存储并处理冲突)(素数+冲突处理)
The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to beH(key)=key%TSiz...
scalarprod.pdf
math scalar product math problem
24点(vb版)
a simple game which names &quot;;math 24&quot;;.
HDU 1098 Ignatius's puzzle(据说是规律题,然而我们要以正确的姿势搞定它)
HDU 1098 Ignatius's puzzle(据说是规律题,然而我们要以正确的姿势搞定它)
算法模板之矩阵快速幂(HDU 1757 A Simple Math Problem)
模板总结归纳:typedef long long ll;nnconst int maxn = 110;nconst int MOD = 1e9+7;n#define mod(x) ((x)%MOD)nnint n;nnstruct mat{n int m[maxn][maxn];n}unit;nnmat operator * (mat a, mat b)n{n mat ret;n ll x;n f...
2017 武大校赛 I: A simple math problem(矩阵快速幂)
问题 I: A simple math problemn时间限制: 1 Sec  内存限制: 512 MBn提交: 21  解决: 8n[提交][状态][讨论版]nn题目描述nnGiven a number n, you should calculate 123456 . . . 11121314 . . . n module 11.nn输入nnA single line w
hdu 1757 A Simple Math Problem(矩阵快速幂基础题)
题目链接:rn题意:就是给出了一个关系式,求f(k)并对他模mrn思路:建立好矩阵的关系,然后就是一个矩阵的快速幂的裸题rn构建矩阵rn|f(10)|      |a0 a1 a2 ...a8 a9|     |f(9)|rn| f(9) |      | 1   0   0 ... 0   0 |      |f(8)|rn| ..... |  =  |.. ... ... ... ..   
HDU 1098 Ignatius's puzzle(数学归纳题or费马小定理)
Ignatius's puzzlenTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)nTotal Submission(s): 8426    Accepted Submission(s): 5842nnnnProblem DescriptionnIgnatius i
【HDU】1757 - A Simple Math Problem(矩阵构造方法 & 快速幂)
点击打开题目rnrnrnrnA Simple Math ProblemrnTime Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)rnTotal Submission(s): 4161    Accepted Submission(s): 2506rnrnrnrnProblem Descr
天天写算法之A Simple Math Problem(矩阵快速幂)
地址:点击打开链接这个题的难点在于如果之前你没有这方面经验的话,估计很难构造这个矩阵,会了构造之后,会写快速矩阵就OK了。代码如下:#include&amp;lt;iostream&amp;gt;n#include&amp;lt;cstdio&amp;gt;n#include&amp;lt;string.h&amp;gt;nusing namespace std;n#define MAX 100000002n#define repf(i,a,b...
文章热词 机器学习教程 Objective-C培训 交互设计视频教程 颜色模型 设计制作学习
相关热词 mysql关联查询两次本表 native底部 react extjs glyph 图标 怎么学习互联网大数据 村干部学习大数据心得