比赛 4043级NOIP2022欢乐赛1st 评测结果 WAWWWWWWWW
题目名称 数字迷阵 最终得分 10
用户昵称 ZRQ 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2022-10-28 22:06:24
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #define ll long long
  4. using namespace std;
  5. ll x,y,Mod;
  6. ll a[4],b[4][4],t[4][4],s[7]={0,3,2,3,3,2};
  7. void poww(int c)
  8. {
  9. while(c)
  10. {
  11. for(int i=1;i<=2;++i)
  12. for(int j=1;j<=2;++j)
  13. t[i][j]=b[i][j],b[i][j]=0;
  14. if(c&1)
  15. {
  16. ll i=(a[1]*t[1][1])%Mod+(a[2]*t[2][1])%Mod,j=(a[1]*t[1][2])%Mod+(a[2]*t[2][2])%Mod;
  17. i%=Mod,j%=Mod;
  18. a[1]=i,a[2]=j;
  19. }
  20. for(int i=1;i<=2;++i)
  21. for(int j=1;j<=2;++j)
  22. for(int k=1;k<=2;++k)
  23. b[i][j]+=t[i][k]*t[k][j]%Mod,b[i][j]%=Mod;
  24. c>>=1;
  25. }
  26. return ;
  27. }
  28. int main()
  29. {
  30. freopen("nummaze.in","r",stdin);
  31. freopen("nummaze.out","w",stdout);
  32. scanf("%lld%lld%lld",&x,&y,&Mod);
  33. a[1]=1;
  34. a[2]=2;
  35. b[1][1]=0;
  36. b[1][2]=b[2][1]=b[2][2]=1;
  37. poww(y-1);
  38. a[3]=(a[1]+a[2])%Mod;
  39. ll tot=a[2]*2%Mod+a[3]*3%Mod;
  40. tot%=Mod;
  41. --x;
  42. ll add=1ll*((x/5)%Mod)*tot%Mod;
  43. x%=5;
  44. for(int i=1;i<=x;++i)
  45. {
  46. add+=a[s[i]];
  47. add%=Mod;
  48. }
  49. add+=a[1];
  50. add%=Mod;
  51. printf("%lld\n",add);
  52. return 0;
  53. }