【bzoj1965】[Ahoi2005]SHUFFLE 洗牌

x*2^m==l (mod n+1)
x=(n/2+1)^m*l mod n+1

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
 
typedef long long LL;
 
#define MOD (LL)(n+1LL)
 
int n,m,l;
 
LL qpow(LL a,LL b)
{
    LL m=a,s=1LL;
    while (b)
    {
        if (b & 1)
            s=(s*m)%(n+1);
        m=(m*m)%(n+1);
       b>>=1;
    }
    return s;
}
 
int main()
{
    scanf("%d%d%d",&n,&m,&l);
    printf("%lld",(qpow((LL)n/2+1,m)*l)%(n+1));
    return 0;
}

  

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
 
typedef long long LL;
 
#define MOD (LL)(n+1LL)
 
int n,m,l;
 
LL qpow(LL a,LL b)
{
    LL m=a,s=1LL;
    while (b)
    {
        if (b & 1)
            s=(s*m)%(n+1);
        m=(m*m)%(n+1);
       b>>=1;
    }
    return s;
}
 
int main()
{
    scanf("%d%d%d",&n,&m,&l);
    printf("%lld",(qpow((LL)n/2+1,m)*l)%(n+1));
    return 0;
}
posted @ 2016-08-11 15:14  Yangjiyuan  阅读(381)  评论(0编辑  收藏  举报