简单矩阵快速幂。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<stack>
using namespace std; long long mod=1e9+;
long long n,A,B,x; struct Matrix
{
long long A[][];
int R, C;
Matrix operator*(Matrix b);
}; Matrix X, Y, Z; Matrix Matrix::operator*(Matrix b)
{
Matrix c;
memset(c.A,,sizeof c.A);
int i, j, k;
for (i = ; i <= R; i++)
for (j = ; j <= C; j++)
for (k = ; k <= C; k++)
c.A[i][j] = (c.A[i][j] + (A[i][k] * b.A[k][j])%mod)%mod;
c.R=R; c.C=b.C;
return c;
} void init()
{
memset(X.A,,sizeof X.A);
memset(Y.A,,sizeof Y.A);
memset(Z.A,,sizeof Z.A); for(int i=;i<=;i++) Y.A[i][i]=;
Y.R = ; Y.C = ; X.A[][]=; X.A[][]=B%mod;
X.A[][]=; X.A[][]=A%mod;
X.R=; X.C=; Z.A[][]=; Z.A[][]=x%mod;
Z.R=; Z.C=;
} void work()
{
while (n)
{
if (n % == ) Y = Y*X;
n = n >> ;
X = X*X;
}
Z = Z*Y; printf("%lld\n", Z.A[][]);
} int main()
{
scanf("%lld%lld%lld%lld",&A,&B,&n,&x);
init();
work();
return ;
}

CodeForces 678D Iterated Linear Function的更多相关文章

  1. codeforces 678D Iterated Linear Function 矩阵快速幂

    矩阵快速幂的题要多做 由题可得 g[n]=A*g[n-1]+B 所以构造矩阵  { g[n] }    =  {A   B}  * { g[n-1]} {   1   }         {0   1 ...

  2. codeforces 678D D. Iterated Linear Function(水题)

    题目链接: D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes i ...

  3. Educational Codeforces Round 13 D:Iterated Linear Function(数论)

    http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...

  4. Educational Codeforces Round 13 D. Iterated Linear Function 水题

    D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...

  5. Educational Codeforces Round 13——D. Iterated Linear Function(矩阵快速幂或普通快速幂水题)

      D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes input ...

  6. Educational Codeforces Round 13 D. Iterated Linear Function 逆元+公式+费马小定理

    D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes input s ...

  7. Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)

    题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h&g ...

  8. CF678D(Iterated Linear Function)

    题目链接:传送门 题目大意:略 题目思路:用题目所给函数推出表达式,然后用等比求和公式得到关系式套用即可(需用乘法逆元),也可直接构造矩阵,用矩阵快速幂求解. 感受:做题时一定要仔细,需要仔细注意什么 ...

  9. 【Henu ACM Round#24 D】Iterated Linear Function

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把B提取出来就是一个等比数列了. 求和一下会发现是这种形式. \(B*\frac{(A^n-1)}{A-1}+A^n*x\) 则求一 ...

随机推荐

  1. OC 截取字符串

    1.定义一个字符串a, 截取a 的某一个部分,复制给b, b必须是int型 NSString *a = @"1.2.30"; int  b= [[a substringWithRa ...

  2. ubuntu下安装BeyondCompare比较工具

    在ubuntu12.04下使用比较工具,这里参考了网上的一个方法来安装BeyondCompare3 首先,下载相关软件: 这里选择了BCompare: http://www.scootersoftwa ...

  3. TreeSize Free 查看文件夹大小 v2.3.3 汉化版

    <b>软件名称: <a href="http://www.bkill.com/download/30740.html"><font color=&qu ...

  4. 从0开始学习blockchain

    http://www.8btc.com/build-your-own-blockchain

  5. bootstrap ch2清除浮动+12

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...

  6. DLL and LIB

    在StackOverflow中看到一个提问“what's the difference between DLL's and LIB's?” 有如下回复值得参考: 回复一:

  7. Windows如何压缩tar.gz格式

    Windows如何压缩tar.gz格式 tar.gz 是linux和unix下面比较常用的格式,几个命令就可以把文件压缩打包成tar.gz格式 然而这种格式在windows并不多见,WinRAR.Wi ...

  8. linux上安装配置samba服务器

    linux上安装配置samba服务器 在linux上安装配置samba服务器 在这给大家介绍一个不错的家伙,samba服务.如果您正在犯愁,如何在Windows和Linux之间实现资源共享,就请看看这 ...

  9. kloxo面板教程-折腾了一天

    ------------------------------------------------------------------------------- 前一晚安装了掉线,不得不重新来,有点慢, ...

  10. svn“Previous operation has not finished; run 'cleanup' if it was interrupted

    今天碰到了个郁闷的问题,svn执行clean up命令时报错“Previous operation has not finished; run 'cleanup' if it was interrup ...