首页 > 代码库 > BZOJ 1965 洗牌

BZOJ 1965 洗牌

答案((n/2+1)^m*l)%(n+1)。

#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespace std;long long n,m,l;long long mul(long long a,long long b){    long long d=(long long)floor(a*(long double)b/(n+1)+0.5);    long long ret=a*b-d*(n+1);    if (ret<0) ret+=n+1;    return ret;}long long f_pow(int a,int b){    int ans=1,base=a;    while (b)    {        if (b&1) ans=mul(ans,base)%(n+1);        base=mul(base,base)%(n+1);        b>>=1;    }    return ans%(n+1);}int main(){    scanf("%lld%lld%lld",&n,&m,&l);    printf("%lld\n",mul(l,f_pow(n/2+1,m))%(n+1));    return 0;}

 

BZOJ 1965 洗牌