码迷,mamicode.com
首页 > Windows程序 > 详细

SAC#1 - 组合数

时间:2017-08-19 18:35:00      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:组合   span   family   color   res   ret   cout   ++   main   

P3414 SAC#1 - 组合数

组合数的性质,求(1<<(n-1))%mod即可。其实要快速幂。

 

#include<bits/stdc++.h>
#define MOD 6662333
using namespace std;
unsigned long long n;

unsigned long long p(unsigned long long x)
{
    unsigned long long t=2;
    while(x%2==0)
    {
        t*=t;
        t%=MOD;
        x>>=1;
    }
    unsigned long long result=1;
    while(x>0)
    {
        if(x%2==1)
        {
            result*=t;
            result%=MOD;    
        }
        x>>=1;
        t*=t;
        t%=MOD;
    }
    return result%MOD;
}

int main()
{
  cin>>n;
  n--;
  cout<<p(n);
return 0; 
}

 

SAC#1 - 组合数

标签:组合   span   family   color   res   ret   cout   ++   main   

原文地址:http://www.cnblogs.com/war1111/p/7397276.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!