zoukankan      html  css  js  c++  java
  • 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=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;
    }
  • 相关阅读:
    列表常用方法及演示
    print >> 重定向
    简单字符串过滤练习
    None,Python 的 Null 对象,布尔值
    Time模块简单学习
    str()与repr(),input()与raw_input()
    布尔数,__nonzero__()
    字符串内建函数
    标准类型内建函数
    客户端precommit hook参数
  • 原文地址:https://www.cnblogs.com/Kurokey/p/5587538.html
Copyright © 2011-2022 走看看