HDU5895 Mathematician QSC(经典数论集合题)(一点点更新)

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);
 }
 }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值