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);
}
}
return list.get(x);
}
}

``````
0

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 】（矩阵快速幂）

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证书错误解决办法

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 一个调度问题 好难的动态规划

Python安装及Scrapy配置中遇到的BUG及解决方案

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

Problem A: 类的初体验
HomernWeb BoardrnProblemSetrnStandingrnStatusrnStatisticsrnrnrnrnrnrnrnProblem A: 类的初体验rnTime Limit: 1 Sec  Memory Limit: rn128 MBrnSubmit: 723  Solved: 661rn[Submit][Status][Webrn Board]rnDescription

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

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

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(据说是规律题,然而我们要以正确的姿势搞定它)

2017 武大校赛 I: A simple math problem（矩阵快速幂）

hdu 1757 A Simple Math Problem（矩阵快速幂基础题）

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（矩阵构造方法 & 快速幂）