zoukankan      html  css  js  c++  java
  • bzoj 2875: [Noi2012]随机数生成器

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #define ll long long
     5 using namespace std;
     6 ll x[2][2],y[2][2],m,a,c,x0,n,g;
     7 ll chen1(ll a1,ll a2)
     8 {
     9     long long a3;
    10     if(!a2)
    11       return 0;
    12     a3=chen1(a1,a2>>1);
    13     a3=(a3+a3)%m;
    14     if(a2&1)
    15       a3=(a3+a1)%m;
    16     return a3;
    17 }
    18 void chen(ll x1[2][2],ll x2[2][2])
    19 {
    20     long long x3[2][2];
    21     memset(x3,0,sizeof(x3));
    22     for(int i=0;i<2;i++)
    23       for(int j=0;j<2;j++)
    24         for(int k=0;k<2;k++)
    25           x3[i][j]=(x3[i][j]+chen1(x1[i][k],x2[k][j]))%m;
    26     for(int i=0;i<2;i++)
    27       for(int j=0;j<2;j++)
    28         x1[i][j]=x3[i][j];
    29 }
    30 int main()
    31 {
    32     scanf("%lld%lld%lld%lld%lld%lld",&m,&a,&c,&x0,&n,&g);
    33     x[0][0]=1;
    34     x[1][1]=1;
    35     y[0][0]=a;
    36     y[0][1]=c;
    37     y[1][1]=1;
    38     for(;n;)
    39       {
    40         if(n%2)
    41           chen(x,y);
    42         chen(y,y);
    43         n>>=1;
    44       }
    45     printf("%lld
    ",(chen1(x[0][0],x0)+x[0][1])%m%g);
    46     return 0;
    47 }

    矩阵乘法

  • 相关阅读:
    将HTML格式的String转化为HTMLElement
    程序执行效率
    Oracle之sql追踪
    单行bash、shell、perl命令
    主机安装
    时间序列分析
    R统计图
    需求分析
    oracle数据导入导出
    linux权限问题
  • 原文地址:https://www.cnblogs.com/xydddd/p/5308977.html
Copyright © 2011-2022 走看看