首页 > 其他 > 详细

【bzoj1965】[Ahoi2005]SHUFFLE 洗牌

时间:2016-08-11 15:51:44      阅读:223      评论:0      收藏:0      [点我收藏+]

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;
}

【bzoj1965】[Ahoi2005]SHUFFLE 洗牌

原文:http://www.cnblogs.com/yangjiyuan/p/5761035.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!