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

题意:杨辉三角第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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值