zoukankan      html  css  js  c++  java
  • 【Henu ACM Round#24 D】Iterated Linear Function

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    把B提取出来就是一个等比数列了。 求和一下会发现是这种形式。 $B*frac{(A^n-1)}{A-1}+A^n*x$ 则求一下乘法逆元 写个快速幂就好 A-1的逆元就是$(A-1)^{MOD-2}$

    要注意A=1的情况。
    然后n最大可能为10^18
    所以乘的时候要先对其取模
    不然会乘爆

    【代码】

    #include <bits/stdc++.h>
    #define LL long long
    using namespace std;
    
    const LL MOD = 1e9 + 7;
    
    LL A,B,n,x;
    
    LL Pow(LL x,LL y){
        LL temp = 1;
        while (y){
            if (y&1) temp = (temp*x)%MOD;
            x = (x*x)%MOD;
            y>>=1;
        }
        return temp;
    }
    
    int main()
    {
        cin >> A >> B >> n >> x;
        if (A==1){
            cout<<(x + (n%MOD*B%MOD))%MOD;
        }else{
            LL ni = Pow(A-1,MOD-2);
            LL A_n = Pow(A,n);
            LL temp1 = B*ni%MOD*(A_n-1)%MOD;
            temp1 = (temp1+MOD)%MOD;
            temp1 = (temp1 + A_n*x%MOD)%MOD;
            cout<<temp1<<endl;
        }
        return 0;
    }
    
    
  • 相关阅读:
    http返回码
    WCF 超时
    MVC异步
    熔断设计模式
    JAVA学习图
    java io模型
    keep alive 长连接
    Java异常处理 误区
    架构的本质
    Repository模式
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8861856.html
Copyright © 2011-2022 走看看