CF678D(Iterated Linear Function)
题目链接:传送门
题目大意:略
题目思路:用题目所给函数推出表达式,然后用等比求和公式得到关系式套用即可(需用乘法逆元),也可直接构造矩阵,用矩阵快速幂求解。
感受:做题时一定要仔细,需要仔细注意什么时候需要使用%,此题因为%使用不当,WA3次
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 100005
#define maxn 20005
typedef pair<int,int> PII;
typedef long long LL; long long a,b,n,x,ans;
LL ksm(LL x,LL y){
LL res=;
while(y){
if(y&)res=res*x%MOD;
y>>=;
x=x*x%MOD;
}
return res;
} int main(){
int i,j,group;
cin>>a>>b>>n>>x;
if(a==)cout<<(x+n%MOD*b%MOD)%MOD<<endl;
else{
LL t=ksm(a,n);
ans=(t*x%MOD+(t-)*ksm(a-,MOD-)%MOD*b%MOD)%MOD;
cout<<ans<<endl;
}
return ;
}
CF678D(Iterated Linear Function)的更多相关文章
- Educational Codeforces Round 13 D:Iterated Linear Function(数论)
http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...
- 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 水题
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 ...
- codeforces 678D Iterated Linear Function 矩阵快速幂
矩阵快速幂的题要多做 由题可得 g[n]=A*g[n-1]+B 所以构造矩阵 { g[n] } = {A B} * { g[n-1]} { 1 } {0 1 ...
- Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h&g ...
- CodeForces 678D Iterated Linear Function
简单矩阵快速幂. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm& ...
- 【Henu ACM Round#24 D】Iterated Linear Function
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把B提取出来就是一个等比数列了. 求和一下会发现是这种形式. \(B*\frac{(A^n-1)}{A-1}+A^n*x\) 则求一 ...
随机推荐
- C/C++ 编程计算2的100万次方(m的n次方),超长结果输出文件
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string> ...
- 哈希key个数
$length = keys %hashname; 则$length中得到的直接是该hash的key的个数.
- js检测回车符
在说检测回车符之前,需要了解keydown和keypress的区别 比如你可以将检测事件绑定在input上,如下所示: <input name="remark" id=&qu ...
- windows服务器详细安全设置
1).系统安全基本设置 1.安装说明:系统全部NTFS格式化,重新安装系统(采用原版win2003),安装杀毒软件(Mcafee),并将杀毒软件更新,安装sp2补钉,安装IIS(只安装必须的组件),安 ...
- python3安装scrapy问题解决
scrapy py3.5安装 pip install scrapy 直接安装失败 第一个错误 building 'lxml.etree' extension 使用 pip install lxml 安 ...
- ubuntu彻底干净卸载MySQL、Apache2、Php的方法(各版本通用
一.卸载删除 mysql 1 sudo apt-get autoremove --purge mysql-server-5.0 2 sudo apt-get remove mysql-server ...
- God web
http://my.csdn.net/yerenyuan_pku http://evilcos.me/?p=336 https://www.zhihu.com/question/21606800 st ...
- 当一个线程进入一个对象的synchronized方法A之后,其他线程是否可进入此对象的synchronized方法B?
给出答案: 是不能的,其他线程只能访问该对象的非同步方法,同步方法则不能进入; 因为非静态方法上的synchronized修饰符要求执行方法时要获得对象的锁,如果已经进入A方法,说明对象锁已经被取
- PHP 操作SQLite
连接数据库 下面的 PHP 代码显示了如何连接到一个现有的数据库.如果数据库不存在,那么它就会被创建,最后将返回一个数据库对象. <?php class MyDB extends SQLite3 ...
- Unity—JsonFx序列化场景
场景数据类: /// <summary> /// 关卡数据 /// </summary> public class LevelData { //关卡名称 pub ...