HDU5895 Mathematician QSC(经典数论集合题)(一点点更新)
来源:互联网 发布:怎样购买空间和域名 编辑:程序博客网 时间:2024/06/07 18:15
Mathematician QSC
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 142 Accepted Submission(s): 66
Problem Description
QSC dream of becoming a mathematician, he believes that everything in this world has a mathematical law.
Through unremitting efforts, one day he finally found the QSC sequence, it is a very magical sequence, can be calculated by a series of calculations to predict the results of a course of a semester of a student.
This sequence is such like that, first of all,f(0)=0,f(1)=1,f(n)=f(n−2)+2∗f(n−1)(n≥2)Then the definition of the QSC sequence is g(n)=∑ni=0f(i)2. If we know the birthday of the student is n, the year at the beginning of the semester is y, the course number x and the course total score s, then the forecast mark is xg(n∗y)%(s+1).
QSC sequence published caused a sensation, after a number of students to find out the results of the prediction is very accurate, the shortcoming is the complex calculation. As clever as you are, can you write a program to predict the mark?
Input
First line is an integer T(1≤T≤1000).
The next T lines were given n, y, x, s, respectively.
n、x is 8 bits decimal integer, for example, 00001234.
y is 4 bits decimal integer, for example, 1234.
n、x、y are not negetive.
1≤s≤100000000
Output
For each test case the output is only one integer number ans in a line.
Sample Input
2
20160830 2016 12345678 666
20101010 2014 03030303 333
Sample Output
1
317
Source
2016 ACM/ICPC Asia Regional Shenyang Online
题意: 给你 n,y,x,s 问 (x^g(n∗y))%(s+1),gn=.∑(0--n)fi^2 ,fn:f(0)=0,f(1)=1,f(n)=f(n−2)+2∗f(n−1)(n≥2)
题解:题中给出fn的公式,构建两个矩阵 | 2,1| 和 | fn, 0 |
| 1,0 | | f(n-1),0 |
矩阵快速幂求出fn,打表gn,发现gn=fn*f(n+1)/2, 这样我们完成了第一步。剩下的学了再补。。。。
#include<stdio.h>#include<string.h>typedef struct haha { int mar[3][3]; }marty; marty a,c; int n,m; marty multi(struct haha a1,struct haha a2) { marty temp; int i,j,k; for(i=0;i<3;i++) for(j=0;j<3;j++) { temp.mar[i][j]=0; for(k=0;k<3;k++) { temp.mar[i][j]+=(a1.mar[i][k]*a2.mar[k][j]); } } return temp;}marty matrix_binary(int k){ marty b; memset(b.mar,0,sizeof(b.mar)); b.mar[0][0]=2; b.mar[0][1]=0; b.mar[1][0]=1; b.mar[1][1]=0; while(k) { if(k & 1) b = multi(a,b); a = multi(a,a); k = k >> 1; } return b; } int main() { a.mar[0][0]=2; a.mar[0][1]=1; a.mar[1][0]=1; a.mar[1][1]=0; while(scanf("%d",&n)) { c=matrix_binary(n-2); } }
- HDU5895 Mathematician QSC(经典数论集合题)(一点点更新)
- hdu5895 Mathematician QSC(矩阵快速幂+逆元+降幂)
- 【HDU5895【公式转化 矩阵快速幂 欧拉定义】Mathematician QSC 递推数列前n平方项和 (转)
- HDU5895 Mathematician QSC(构造矩阵+矩阵快速幂+幂次循环节)
- HDU 5895 Mathematician QSC(欧拉定理推广)
- Mathematician QSC(欧拉定理+矩阵快速幂)
- HDU 5895 Mathematician QSC(逆元应用+矩阵快速幂+数论知识)——2016 ACM/ICPC Asia Regional Shenyang Online
- Hdu 5895 Mathematician QSC
- HDU-5895 Mathematician QSC
- HDU 5895 Mathematician QSC
- HDU 5895 Mathematician QSC
- 【HDU5895 2016 ACM ICPC Asia Regional Shenyang Online D】【公式转化 矩阵快速幂 欧拉定义】Mathematician QSC 递推数列前n平方项和
- HDU 5895&&2016 ACM/ICPC Asia Regional Shenyang Online1004 Mathematician QSC [矩阵加速+欧拉降幂]【数论】
- hdoj 5895 Mathematician QSC 【数论----矩阵快速幂求解类斐波那契数列】
- 2016 ACM/ICPC Asia Regional Shenyang Online HDU 5895 Mathematician QSC(矩阵快速幂+高次幂取模)★ ★
- HDU 5895 Mathematician QSC (矩阵快速幂 + 逆元应用 + 指数循环节 + 欧拉函数)
- QSC and Master(dp)
- 数论总结(持续更新)
- 安装Sql Server Management Studio 出现的问题:哈希值不正确(0x80091007)
- Mfsmaster宕机时回复mfsmaster服务(至少两个节点)
- 将Eclipse代码导入到AndroidStudio的两种方式
- 8. String to Integer (atoi)(将输入的字符串转化为整数)
- oozie workflow.xml 综合案例
- HDU5895 Mathematician QSC(经典数论集合题)(一点点更新)
- SQLSERVER 解决SQLServer 2008安装时代理服务提供的凭据无效的方法
- Linux 下mysql安装
- Oracle序列
- 1.2.1. 标准输入与输出对象
- asdf
- 我的一个新的并行优化定理
- MYSQL explain详解
- yum