sdut 2605 不能用快速幂的快速幂

sdut真是一个神奇的网站,编译器g++竟然不识别%I64d,必须lld才行,真坑

#include<iostream>//哈希大法好
#include<cstdio>
using namespace std;
#define ll long long
ll n,a,b,m,P,K,A;
const int maxn=33333;
ll fro[maxn+5],beh[maxn+5],res,cas;
void init()
{
    int i;
    ll tp;
    for(beh[0]=1,res=0,i=1;i<=maxn;i++)
        beh[i]=(beh[i-1]*A)%P;
    for(fro[0]=1,tp=beh[maxn],i=1;i<=maxn;i++)
        fro[i]=(fro[i-1]*tp)%P;
}
void solve()
{
    init();
    ll fx=K;
    for(int i=1;i<=n;i++)
    {
        res=(res+beh[fx%maxn]*fro[fx/maxn]%P)%P;
        fx=(a*fx+b)%m;
    }
    printf("Case #%lld: %lld\n",++cas,res);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--&&scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&n,&A,&K,&a,&b,&m,&P)!=EOF)
        solve();
    return 0;
}


/***************************************************
User name: 杨凡
Result: Accepted
Take time: 1244ms
Take Memory: 676KB
Submit time: 2017-03-06 17:54:52
****************************************************/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值