From today onwards, there are network races.
Today is the CCPC National game online game.
I hope everything goes well. I hope I can go to Dalian once again.
Test instructions
It's clear you're asking for sn=[a+sqrt. (b) ^n]%m
Ideas:
At first, I thought it was a water problem, a violent one.
Surf the internet to know that is the fast power
And the derivation of the characteristic equation is subtle.
In particular, the conjugate-phase offset structure is really too much to see.
(Transferred from a great God blog)
Characteristic equation is c^2=-2*a*c+ (a*a-b)
And then solve it with a fast power
Temporarily learned the next matrix fast power
I can tell from this question.
Get ACM really want to learn
This is not a high-number line-generation probability score for school cognition.
But a mathematical mindset.
It's the most important thing to get a formula that can be deduced.
The scores on the school test papers can only prove your ability to test.
It's useless to have a higher score without mathematical thinking.
From such a question can see a person's mathematics in the end is good or not
My road is far away ...
1#include <stdio.h>2#include <iostream>3#include <algorithm>4#include <math.h>5#include <string.h>6#include <string>7#include <map>8#include <Set>9#include <vector>Ten#include <queue> One #defineM (A, B) memset (A,b,sizeof (a)) A using namespacestd; -typedefLong Longll; - ll M; the structmatrix{ -ll mt[2][2]; -Matrix Mul (Matrix A,matrix b) {//matrix multiplication - Matrix C; +M (C.MT,0); - for(intI=0;i<2; i++) + for(intj=0;j<2; j + +) A for(intk=0;k<2; k++) atc.mt[i][j]+= (A.mt[i][k]*b.mt[k][j])%m;//This is going to be modulo m not because of the overflow WA - returnC; - } -Matrix Fast_pow (Matrix A,ll MoD) {//Fast Power - matrix result; - for(intI=0;i<2; i++) in for(intj=0;j<2; j + +) -Result.mt[i][j]= (i==j); to while(MoD) { + if(mod%2) result=Mul (result,a); -A=Mul (a,a); theMod/=2; * } $ returnresult;Panax Notoginseng } - }mt; the intMain () { + ll A,b,n; A while(SCANF ("%i64d%i64d%i64d%i64d", &a,&b,&n,&m)! =EOF) { themt.mt[0][0]=2*A; +mt.mt[0][1]=1; -mt.mt[1][0]=b-a*A; $mt.mt[1][1]=0; $Mt=mt.fast_pow (mt,n-1); -ll Ans= ((2*a*mt.mt[0][0]+2*mt.mt[1][0])%m+m)%m;//take two times here because the first modulo may be negative . -printf"%i64d\n", ans); the } - return 0;Wuyi } the /* - Wu 2 3 1 - 2 3 2 About 2 2 1 $ - */
[An Ac a day ^_^] hdu 4565 mathematical deduction + matrix fast Power