首页 > 技术文章 > CF678D(Iterated Linear Function)

Kurokey 2016-06-15 15:05 原文

题目链接:传送门

题目大意:略

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

感受:做题时一定要仔细,需要仔细注意什么时候需要使用%,此题因为%使用不当,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=1;
    while(y){
        if(y&1)res=res*x%MOD;
        y>>=1;
        x=x*x%MOD;
    }
    return res;
}

int main(){
    int i,j,group;
    cin>>a>>b>>n>>x;
    if(a==1)cout<<(x+n%MOD*b%MOD)%MOD<<endl;
    else{
        LL t=ksm(a,n);
        ans=(t*x%MOD+(t-1)*ksm(a-1,MOD-2)%MOD*b%MOD)%MOD;
        cout<<ans<<endl;
    }
    return 0;
}

 

推荐阅读