题目链接:传送门

题目大意:略

题目思路:用题目所给函数推出表达式,然后用等比求和公式得到关系式套用即可(需用乘法逆元),也可直接构造矩阵,用矩阵快速幂求解。

感受:做题时一定要仔细,需要仔细注意什么时候需要使用%,此题因为%使用不当,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)的更多相关文章

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

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

  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 水题

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

  4. 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 ...

  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 s ...

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

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

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

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

  8. CodeForces 678D Iterated Linear Function

    简单矩阵快速幂. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm& ...

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

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

随机推荐

  1. 【PHP原生】获取字符串所有汉字首字母和首个汉字首字母

    1.废话不多说,看代码,获取字符串汉字首字母,兼容GBK和UTF-8 <?php //获取单个汉字拼音首字母.注意:此处不要纠结.汉字拼音是没有以U和V开头的 function getfirst ...

  2. IE浏览器右键菜单分享扩展

    (如果本页面没有自动下载,请点这里下载) IE浏览器分享工具安装步骤:1.发起下载请求后,屏幕上会弹出文件保存对话框,将文件保存到您电脑本地的磁盘中 2.双击刚才下载的安装文件,将JiaThis_Sh ...

  3. mongodb - 查看正在执行的操作

    查看正在执行的操作 db.currentOp() 查看系统执行的操作 db.currentOp(True) kill正在执行的操作 db.killOp(<operation id>) 示例 ...

  4. void *指针的加减运算

    1.手工写了一个程序验证void *指针加减运算移动几个字节: //本程序验证空类型指针减1移动几个字节 #include <stdio.h> int main(int argc, cha ...

  5. 设计模式_CallBack

    一.基本概念 if you call me, i will call back 什么是回调函数  回调函数(callback Function),顾名思义,用于回调的函数. 回调函数只是一个功能片段, ...

  6. Web前端的状态管理(State Management)

    背景 我相信很多朋友跟我一样,初次听到什么Flux, Redux, Vuex,状态管理的时候是一脸懵逼的.因为在外面之前前端大部分开发的时候,根本没有那么多的概念.自从ReactJS火爆后,什么Flu ...

  7. 配置taglib的uri的2种方法

    推荐方法1 1.把uri写在tld文件中,tld放在WEB-INF文件夹下,例如: <short-name>就对应了你在jsp中引用的时候<%@ taglib prefix=&quo ...

  8. JAVA中使用P和Q分量计算N和D进行RSA运算

    最近在使用Java中需要使用PQ形式的私钥进行RSA加解密运算,本来以为Java中应该很多类似的例子,发现所有的例子都是从ND形式的私钥,竟然没有人用分量P和Q计算N和D进行运算.对Java使用RSA ...

  9. MapReduce实战(六)共同粉丝

    需求: 利用mapReduce实现类似微博中查找共同粉丝的功能.如下: A:B,C,D,F,E,OB:A,C,E,KC:F,A,D,ID:A,E,F,LE:B,C,D,M,LF:A,B,C,D,E,O ...

  10. 如何Vue-cli开始使用在Vue.js项目中启动TDD(测试驱动开发)

    通常,使用测试驱动开发(TDD)最困难的部分是开始.你必须下载带有奇怪依赖项的软件包,让测试套件与你的构建系统协同工作,然后你必须弄清楚如何编写一个测试!难怪这么多的开发者在你提起它的时候就开始跑开了 ...