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)个。
解析:
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; }
相关文章推荐
- HDU4349—Lucas定理的应用
- Lucas定理应用分析——大组合数取模
- 教你一波Lucas(卢卡斯)定理在数论解题中的应用
- HDU 3037 Saving Beans(Lucas定理的直接应用)
- HDU - 5446 Unknown Treasure (数论部分定理的综合应用,lucas+CRT)
- BZOJ 4403:浅谈Lucas定理应用及组合数建模
- HDU 3037 Saving Beans(Lucas定理的直接应用)
- Lucas定理在ACM中的应用
- FZU 2020 组合(Lucas定理的应用)
- HDU 3037 Saving Beans(Lucas定理的直接应用)
- HDU 4349——Lucas定理的巧妙应用
- Lucas定理的应用
- HDU 4349 Xiao Ming's Hope (Lucas定理的应用)
- Lucas定理及其应用
- [BZOJ4591][SHOI2015]超能粒子炮·改(Lucas定理+数位DP)
- lucas定理模板
- 贝叶斯推断及其互联网应用(一):定理简介
- poj 3146 Interesting Yang Hui Triangle (Lucas定理)
- pick定理的应用
- bzoj 1951: [Sdoi2010]古代猪文 (Lucas定理+中国剩余定理)