CodeForces 678D Iterated Linear Function
简单矩阵快速幂。
#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的更多相关文章
- codeforces 678D Iterated Linear Function 矩阵快速幂
矩阵快速幂的题要多做 由题可得 g[n]=A*g[n-1]+B 所以构造矩阵 { g[n] } = {A B} * { g[n-1]} { 1 } {0 1 ...
- codeforces 678D D. Iterated Linear Function(水题)
题目链接: D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes i ...
- Educational Codeforces Round 13 D:Iterated Linear Function(数论)
http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...
- Educational Codeforces Round 13 D. Iterated Linear Function 水题
D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...
- 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 ...
- 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 ...
- Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h&g ...
- CF678D(Iterated Linear Function)
题目链接:传送门 题目大意:略 题目思路:用题目所给函数推出表达式,然后用等比求和公式得到关系式套用即可(需用乘法逆元),也可直接构造矩阵,用矩阵快速幂求解. 感受:做题时一定要仔细,需要仔细注意什么 ...
- 【Henu ACM Round#24 D】Iterated Linear Function
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把B提取出来就是一个等比数列了. 求和一下会发现是这种形式. \(B*\frac{(A^n-1)}{A-1}+A^n*x\) 则求一 ...
随机推荐
- 【笔记】虚拟机用Xshell登陆报错“ssh服务器拒绝了密码”解决方法
自己本地安装了VMware Workstation之后,创建虚拟机,一开始是可以用Xshell登陆的,几天后,重启了电脑以及虚拟机,发现无法登陆了,还没有输入密码就有如下报错信息 这时候开始排查原因, ...
- SpringMVC集成shrio框架
使用SHIRO的步骤:1,导入jar2,配置web.xml3,建立dbRelm4,在Spring中配置 添加所需jar包: <!--Apache Shiro所需的jar包--> <d ...
- 2015 Multi-University Training Contest 9
1001 Expression 式子不好推啊.见官方题解. 式子知道就方便了.处理好组合数和阶乘. 按区间长度从小到大递推完就好. # include <iostream> # inclu ...
- 已知整数m,n,p,q适合(m-p)|(mn+pq)证明:(m-p)|(mq+np)(整除理论1.1.5)
已知整数m,n,p,q适合(m-p)|(mn+pq)证明:(m-p)|(mq+np) 证明: 令(mn+pq)—(mq+np) =mn-np+pq-mq =n(m-p)+q(p-m) =(n-q)(m ...
- 杭电15题 The Cow Lexicon
Problem Description Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, eac ...
- 5.编写Java应用程序。首先,定义描述学生的类——Student,包括学号(int)、 姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age) 用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类—— TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测 试St
Student类: package com.bao; public class Student { int stuNo;String name,sex;int age,weight; Student( ...
- linker command failed with exit code 1 (use -v to see
转自 :http://www.reader8.cn/jiaocheng/20131022/2003334.html Undefined symbols for architecture http:// ...
- treecnt
treecnt ﹡ LH (命题人) 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 给定一棵n个节点的树,从1到n标号.选择k个点,你需要选择一些边使得这k个点通过选择 ...
- 批量创建IP方法
以下教程,将告诉大家如何在Windows系统中通过命令行,批量添加IP.目标,在本机的的网卡名称为“本地连接”的网卡中,批量添加192.168.1段的ip地址,起开始IP为10,每次增加1,知道22为 ...
- Number-guessing Game
Number-guessing Game Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Othe ...