您的位置:首页 > 产品设计 > UI/UE

poj 3146 Interesting Yang Hui Triangle(lucas定理的应用)

2013-11-18 22:28 197 查看
题意:杨辉三角第n+1行有多少数不被p整除??

解析:

lucas定理:设p为质数,a,b为两正整数,且a,b在p进制下表示为 a=(ak……,a0),b=(bk……,b0) 0=<ai,bi<p

证明 c[a,b]=c[ak,bk]*……*c[a0,b0](mod p)

证:

p为质数时易证 (1+x)^p=1+x^p(mod p)

(1+x)^a=(1+x)^(ak*p^k)……(1+x)^(a0) (mod p)

=(1+x^(p^k))^ak……(1+x)^a0(mod p) (1)

x^b在(1)右边式子的系数为c[ak,bk]*……*c[a0,b0]。

从而的证 c[a,b]=c[ak,bk]*……*c[a0,b0](mod p)

根据这个结论 我们可知c[a,b]=0(mod p) 当且仅当 存在bi>ai,而我们知道题目所求的bi是从c(n,0)一直到c(N,N),所以包括所有的ai ,而对于其中的一个b有 ai+1中取法, 所有的即为 TT(ai+1)

所以c[n,m]不被p整除的数有 TT(ai+1) (0=<i<=k)个。

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
#define PI acos(-1.0)
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=200010;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7,STA=8000010;
//const LL LNF=1LL<<60;
const double EPS=1e-8;
const double OO=1e15;
const int dx[4]={-1,0,1,0};
const int dy[4]={0,1,0,-1};
const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}

int main()
{

LL p,n,res;
int t=1;
while(~scanf("%lld%lld",&p,&n)&&p)
{
res=1;
while(n)
{
res=res*(n%p+1)%10000;
n/=p;
}
printf("Case %d: %04lld\n",t++,res);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: