题目链接:传送门

题目大意:略

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

感受:做题时一定要仔细,需要仔细注意什么时候需要使用%,此题因为%使用不当,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. oracle 使用REGEXP_SUBSTR正则表达式拆分字符串

    SELECT REGEXP_SUBSTR ('first field, second field , third field', '[^,]+', 1,rownum) FROM DUAL CONNEC ...

  2. Tomcat版本历史

    https://en.wikipedia.org/wiki/Apache_Tomcat Apache Tomcat versions Series Declared stable Descriptio ...

  3. 用Web API Client 调用 Web API

    安装Web API客户端库 右键单击项目,选择管理 NuGet程序包,选择联机选项,选择全部,在搜索框中输入“Microsoft.AspNet.WebApi.Client”, 搜索结果就是要安装的类库 ...

  4. 微信小程序挑一挑辅助

    1.窗体 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;usi ...

  5. To Use Genymotion

    Chinese Site:http://www.genymotion.cn/ Offical Site:http://www.genymotion.com/  Not available in Chi ...

  6. [Java基础]List,Map集合总结

    java.util包下: Collection    |--List 接口 |----ArrayList |----LinkedList |----Vector |-----Stack |---Set ...

  7. Java Jar maven 下载地址

    Java Jar maven 下载地址 https://repo1.maven.org/maven2/ 根据maven artifactid 查找相关jar

  8. 使用Apache Jmeter进行并发压力测试

    http://blog.jassassin.com/2014/04/17/tools/jmeter/

  9. IDirect3DDevice9::SetTexture的stage参数

    HRESULT IDirect3DDevice9::SetTexture(DWORD Stage, IDirect3DBaseTexture9 *pTexture) 其中Stage并不是“阶段”的意思 ...

  10. c语言循环单链表

    /************************************************************************* > File Name: singleLin ...