• 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;
    }
  • 相关阅读:
    Ext.create() 时的自适应高度和宽度
    C++ builder快捷键大全
    删除右键菜单中的选项
    函数中指针和引用的形参和实参
    一道关于继承和多态的题目
    关于静态对象构造
    关于多态代码和运行结果
    如何使用C++ Builder 6.0连接Access数据库
    BCB中的RTTI机制
    scanf()返回值(转)
  • 原文地址:https://www.cnblogs.com/Kurokey/p/5587538.html
Copyright © 2020-2023  润新知