Topic Link:
Http://acm.zju.edu.cn/changsha/showContestProblem.do?problemId=19
Topic Meaning:
The subject is very obscure. In the K-dimensional space, the start length is L, and the operation becomes l+√ (l* (l+1)). Ask the last%k the number of integers left.
Ideas for solving problems:
Mathematical formula + matrix fast power.
Because it is in the K-dimensional space, it is also required (l+√ (l* (L-1)) ^k The value of the%k after the rounding down.
This question and this year, the Changsha Invitational contest a question, almost, but the problem is to take the whole up, this problem is to take the whole, minus one on the line.
Thinking reference Hdu 4565
Code:
#include <iostream> #include <cmath> #include <cstdio> #include <cstdlib> #include <string > #include <cstring> #include <algorithm> #include <vector> #include <map> #include <set > #include <stack> #include <list> #include <queue> #include <ctime> #define EPS 1e-6 #define INF 0x3f3f3f3f #define PI acos ( -1.0) #define LL long #define Lson l,m, (rt<<1) #define Rson m+1,r, (rt<<1) |
1 #pragma COMMENT (linker, "/stack:1024000000,1024000000") using namespace std;
#define MAXN 3 ll m,a,b;
struct Mar {int r,c;
ll SA[MAXN][MAXN];
void init (int a,int b) {r=a,c=b;
memset (sa,0,sizeof (SA));
}
};
Mar operator * (struct Mar & a,struct Mar & B) {Mar C;
C.init (A.R,B.C);
for (int k=1;k<=a.c;k++) {for (int i=1;i<=c.r;i++) {if (!a.sa[i][k))
Continue
for (int j=1;j<=c.c;j++) { if (!b.sa[k][j]) continue;
C.sa[i][j]= (C.sa[i][j]+a.sa[i][k]*b.sa[k][j])%m;
}} return C;
Mar Ba[35],ans;
void Init () {ba[0].init (2,2);
ba[0].sa[1][1]= (2*a)%m,ba[0].sa[1][2]= ((b-a*a)%m+m)%m;
ba[0].sa[2][1]=1,ba[0].sa[2][2]=0;
for (int i=1;i<32;i++)//2^i {ba[i]=ba[i-1]*ba[i-1];
int main () {ll l,k;
while (~SCANF ("%lld%lld", &k,&l)) {a=l,b=l* (L-1);
M=k;
Init ();
Ans.init (2,1);
ans.sa[1][1]= (2*a)%m,ans.sa[2][1]=2;
for (int i=0;i<32&&k;i++) {if (k&1) {Ans=ba[i]*ans;
} k>>=1;
printf ("%lld\n", (ans.sa[2][1]-1+m)%m);
return 0;
}