麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

poj 3146 Lucas定理的使用

2019-11-11 06:45:51
字體:
來源:轉載
供稿:網友

Harry is a Junior middle student. He is very interested in the story told by his mathematics teacher about the Yang Hui triangle in the class yesterday. After class he wrote the following numbers to show the triangle our ancestor studied.

 1 
 1 1 
 1 2 1 
 1 3 3 1 
 1 4 6 4 1 
 1 5 10 10 5 1 
 1 6 15 20 15 6 1 
1 7 21 35 35 21 7 1
 …… 

He found many interesting things in the above triangle. It is symmetrical, and the first and the last numbers on each line is 1; there are exactlyi numbers on the line i.

Then Harry studied the elements on every line deeply. Of course, his study is comPRehensive.

Now he wanted to count the number of elements which are the multiple of 3 on each line. He found that the numbers of elements which are the multiple of 3 on line 2, 3, 4, 5, 6, 7, … are 0, 0, 2, 1, 0, 4, … So the numbers of elements which are not divided by 3 are 2, 3, 2, 4, 6, 3, …, respectively. But he also found that it was not an easy job to do so with the number of lines increasing. Furthermore, he is not satisfied with the research on the numbers divided only by 3. So he asked you, an erudite expert, to offer him help. Your kind help would be highly appreciated by him.

Since the result may be very large and rather difficult to compute, you only need to tell Harry the last four digits of the result.

Input

There are multiple test cases in the input file. Each test case contains two numbersP and N, (P < 1000, N ≤ 109), whereP is a prime number and N is a positive decimal integer.

P = 0, N = 0 indicates the end of input file and should not be processed by your program.

Output

For each test case, output the last four digits of the number of elements on theN + 1 line on Yang Hui Triangle which can not be divided by P in the format as indicated in the sample output.

Sample Input
3 43 480 0Sample Output
Case 1: 0004Case 2: 0012

題意:楊輝三角第n+1層上能被素數p整除的數的個數

Lucas定理:

對于c(n,m)mod p,用a[k]a[k-1]...a[0],b[k]b[k-1]...b[0]來分別表示n和m對應的素數p進制數,即

n = a[k]*p^k + a[k-1]*p^(k-1) + ... + a[1]*p + a[0]m = b[k]*p^k + b[k-1]*p^(k-1) + ... + b[1]*p + b[0]

C(n,m)mod p=[C(a[k],b[k])×C(a[k-1],b[k-1])×...×C(a[0],b[0])]mod p

楊輝三角對應著C(n,m)矩陣

if i>=j  c(i,j)!=0

if i<j     c(i,j)=0

對于[C(a[k],b[k])×C(a[k-1],b[k-1])×...×C(a[0],b[0])]mod p!=0的種數,其中由于n確定,所以a[]確定,種數由b[]決定

c(i,j)必須全不為0,才能被p整除

C(n,m)=n*(n-1)*(n-2)*……*(n-m+1)/(1*2*3*……*m) ,a[]和b[]都小于p,無法被p整除

所以每項都要b[i]>=a[i],0=<i<=k

每一項的個數為(a[i]+1),即b=0~a[i];

總數為(a0+1)(a1+1)......(ak+1);

#include<iostream>#include<cmath>#include<cstring>#include<cstdio>#include<algorithm>#define inf 0x3f3f3f3f#define ll long long#define mod 10000using namespace std;int main(){    int p,n;    int kcase=1;    while(cin>>p>>n)    {        if(p==0&&n==0)            return 0;        int ans=1;        while(n)        {            ans=(ans*(n%p+1))%mod;//原題需要保留4位數字            n=n/p;        }        printf("Case %d: %04d/n",kcase++,ans);    }    return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 免费在线观看国产精品 | 91在线精品亚洲一区二区 | 国产在线久| 国产精品久久久久久久久粉嫩 | 欧美亚洲国产成人 | 精品中文字幕在线播放 | 久久亚色| av噜噜噜噜 | 911视频免费版| 精品成人av一区二区在线播放 | 91看片淫黄大片欧美看国产片 | 国产成人自拍av | 史上最强炼体老祖动漫在线观看 | 激情小说区| 青青草最新网址 | 国产精品免费看 | 91免费高清视频 | 日本网站一区 | 4p一女两男做爰在线观看 | 天天草夜夜骑 | 9丨九色丨国产 | 国产免费美女 | 久久精品欧美一区 | 羞羞网站在线看 | 久久久久国产成人免费精品免费 | 国产一区二区欧美 | 舌头伸进添的我好爽高潮网站 | 欧美成人三级大全 | 黄色片网站免费在线观看 | 成年人观看免费视频 | 成人精品久久 | 在线播放91 | 国产在线精品区 | 黄色免费入口 | 性爱在线免费视频 | va免费视频 | 免费观看一级黄色片 | 国产88久久久国产精品免费二区 | 欧美wwwwww | 中文字幕视频在线播放 | 国产成人精品一区二区仙踪林 |