锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 瀵逛簬緇欏畾鐨勪竴涓礌鏁?p 錛?φ(p) = p -1銆傚垯瀵逛簬姝f暣鏁?n = pk 錛?/p> 鍋囪 p, q鏄袱涓簰璐ㄧ殑姝f暣鏁幫紝鍒?p * q 鐨勬鎷夊嚱鏁頒負 φ(p * q) = φ(p) * φ(q) 錛?gcd(p, q) = 1 銆?/p> 浠繪剰涓涓暣鏁?n 閮藉彲浠ヨ〃紺轟負鍏剁礌鍥犲瓙鐨勪箻縐負錛?/p> 鏍規嵁鍓嶉潰涓や釜緇撹錛屽緢瀹規槗寰楀嚭瀹冪殑嬈ф媺鍑芥暟涓猴細 瀵逛簬浠繪剰 n > 2錛?span style="line-height: 24px; font-weight: bold; ">2 | Φ(n) ,鍥犱負蹇呭瓨鍦?nbsp; pi -1 鏄伓鏁般?/p> 鍏跺疄灝辨槸鎶夾涓孩鐞冿紝B涓鐞冨垎鎴恘+1鍫嗭紙闄鍫嗗榪樻湁涓鍫嗗氨鏄病鏈夋斁鍏ョ洅涓殑錛夈?br>鎬濊礬寰堥噸瑕侊紝 榪樻湁涓涓敞鎰忕偣褰撲笖浠呭綋n=20,a= 15 ,b=15鏃朵細瓚呭嚭long long 鑼冨洿銆傛墍浠ョ壒孌婂鐞?br> Encoding schemes are often used in situations requiring encryption or information storage/transmission economy. Here, we develop a simple encoding scheme that encodes particular types of words with five or fewer (lower case) letters as integers.
Consider the English alphabet {a,b,c,...,z}. Using this alphabet, a set of valid words are to be formed that are in a strict lexicographic order. In this set of valid words, the successive letters of a word are in a strictly ascending order; that is, later letters in a valid word are always after previous letters with respect to their positions in the alphabet list {a,b,c,...,z}. For example,
abc aep gwz
are all valid three-letter words, whereas
aab are cat
are not.
For each valid word associate an integer which gives the position of the word in the alphabetized list of words. That is:
Your program is to read a series of input lines. Each input line will have a single word on it, that will be from one to five letters long. For each word read, if the word is invalid give the number 0. If the word read is valid, give the word's position index in the above alphabetical list.
The input consists of a series of single words, one per line. The words are at least one letter long and no more that five letters. Only the lower case alphabetic {a,b,...,z} characters will be used as input. The first letter of a word will appear as the first character on an input line.
The input will be terminated by end-of-file.
The output is a single integer, greater than or equal to zero (0) and less than or equal 83681. The first digit of an output value should be the first character on a line. There is one line of output for each input line.
One curious child has a set of N little bricks. From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Every staircase consists of at least two steps and each step contains at least one brick. Picture gives examples of staircase for N=11 and N=5: Your task is to write a program that reads from input numbers N and writes to output numbers Q - amount of different staircases that can be built from exactly N bricks. The rhyme scheme for a poem (or stanza of a longer poem) tells which lines of the poem rhyme with which other lines. For example, a limerick such as
For a poem or stanza of four lines, there are 15 possible rhyme schemes: aaaa, aaab, aaba, aabb, aabc, abaa, abab, abac, abba, abbb, abbc, abca, abcb, abcc, and abcd.
Write a program to compute the number of rhyme schemes for a poem or stanza of N lines where N is an input value.
鍋囧p鏄川鏁幫紝涓攁,p浜掕川錛岄偅涔?a鐨?p-1)嬈℃柟闄や互p鐨勪綑鏁版亽絳変簬1
鍘嗗彶銆銆涓庤垂椹皬瀹氱悊鐩稿叧鐨勬湁涓涓?/span>涓浗鐚滄兂錛岃繖涓寽鎯蟲槸涓浗鏁板瀹舵彁鍑烘潵鐨勶紝鍏跺唴瀹逛負錛氬綋涓斾粎褰?^(p-1錛?#8801;1(mod p錛夛紝p鏄竴涓川鏁般?/span>銆銆鍋囧p鏄竴涓川鏁扮殑璇濓紝鍒?^(p-1錛?#8801;1(mod p錛夋垚绔嬶紙榪欐槸璐歸┈灝忓畾鐞嗙殑涓涓壒孌婃儏鍐碉級鏄鐨勩備絾鍙嶈繃鏉ワ紝鍋囧2^(p-1錛?#8801;1(mod p錛夋垚绔嬮偅涔坧鏄竴涓川鏁版槸涓嶆垚绔嬬殑錛堟瘮濡?41絎﹀悎涓婅堪鏉′歡浣嗕笉鏄竴涓川鏁幫級銆傚洜姝ゆ暣涓潵璇磋繖涓寽鎯蟲槸閿欒鐨勩備竴鑸涓轟腑鍥芥暟瀛﹀鍦ㄨ垂椹墠2000騫寸殑鏃跺欏氨宸茬粡璁よ瘑涓浗鐚滄祴浜嗭紝浣嗕篃鏈変漢璁や負瀹為檯涓婁腑鍥界寽嫻嬫槸1872騫存彁鍑虹殑錛岃涓哄畠鏃╁氨涓轟漢鎵鐭ユ槸鍑轟簬涓涓瑙c?/span>緙栬緫鏈璇佹槑
銆銆涓銆佸噯澶囩煡璇嗭細銆銆寮曠悊1錛?a target="_blank" style="color: #136ec2; ">鍓╀綑緋?/a>瀹氱悊2銆銆鑻,b,c涓轟換鎰?涓暣鏁幫紝m涓烘鏁存暟錛屼笖錛坢,c)=1錛屽垯褰揳c≡bc(mod m錛夋椂錛屾湁a≡b(mod m)銆銆璇佹槑錛歛c≡bc(mod m錛夊彲寰梐c–bc≡0(mod m錛夊彲寰楋紙a-b)c≡0(mod m錛夊洜涓猴紙m,c)=1鍗砿,c浜掕川錛宑鍙互綰﹀幓錛宎–b≡0(mod m錛夊彲寰梐≡b(mod m)銆銆寮曠悊2錛庡墿浣欑郴瀹氱悊5銆銆鑻涓烘暣鏁頒笖m>1,a[1],a[2],a[3],a[4]錛?#8230;a[m]涓簃涓暣鏁幫紝鑻ュ湪榪檓涓暟涓換鍙?涓暣鏁板m涓嶅悓浣欙紝鍒欒繖m涓暣鏁板m鏋勬垚瀹屽叏鍓╀綑緋匯?/span>銆銆璇佹槑錛氭瀯閫爉鐨勫畬鍏ㄥ墿浣欑郴錛?,1,2錛?#8230;m-1錛夛紝鎵鏈夌殑鏁存暟蹇呯劧榪欎簺鏁存暟涓殑1涓妯鍚屼綑銆傚彇r[1]=0,r[2]=1,r[3]=2,r[4]=3錛?#8230;r=i-1,1<i<=m銆備護錛?錛夛細a[1]≡r[1](mod m),a[2]≡r[2](mod m),a≡r(mod m錛夛紙欏哄簭鍙互涓嶅悓錛夛紝鍥犱負鍙湁鍦ㄨ繖縐嶆儏鍐典笅鎵嶈兘淇濊瘉闆嗗悎{a1,a2,a3,a4錛?#8230;am}涓殑浠繪剰2涓暟涓嶅悓浣欙紝鍚﹀垯蹇呯劧鏈?涓暟鍚屼綑銆傜敱寮忥紙1錛夎嚜鐒跺緱鍒伴泦鍚坽a1,a2,a3,a4錛?#8230;am}瀵筸鏋勬垚瀹屽叏鍓╀綑緋匯?/span>銆銆寮曠悊3錛庡墿浣欑郴瀹氱悊7銆銆璁緈鏄竴涓暣鏁幫紝涓攎>1錛宐鏄竴涓暣鏁頒笖錛坢,b)=1銆傚鏋渁1,a2,a3,a4錛?#8230;am鏄ām鐨勪竴涓畬鍏ㄥ墿浣欑郴錛屽垯ba[1],ba[2],ba[3],ba[4]錛?#8230;ba[m]涔熸瀯鎴愭ām鐨勪竴涓畬鍏ㄥ墿浣欑郴銆?/span>銆銆璇佹槑錛氳嫢瀛樺湪2涓暣鏁癰a鍜宐a[j]鍚屼綑鍗砨a≡ba[j](mod m錛夛紝鏍規嵁寮曠悊1鍒欐湁a≡a[j](mod m錛夈傛牴鎹畬鍏ㄥ墿浣欑郴鐨勫畾涔夊拰寮曠悊4錛堝畬鍏ㄥ墿浣欑郴涓換鎰?涓暟涔嬮棿涓嶅悓浣欙紝鏄撹瘉鏄庯級鍙煡榪欐槸涓嶅彲鑳界殑錛屽洜姝や笉瀛樺湪2涓暣鏁癰a鍜宐a[j]鍚屼綑銆傜敱寮曠悊5鍙煡ba[1],ba[2],ba[3],ba[4]錛?#8230;ba[m]鏋勬垚妯鐨勪竴涓畬鍏ㄥ墿浣欑郴銆?/span>銆銆寮曠悊4錛?a target="_blank" style="color: #136ec2; ">鍚屼綑瀹氱悊6銆銆濡傛灉a,b,c,d鏄洓涓暣鏁幫紝涓攁≡b(mod m),c≡d(mod m錛夛紝鍒欐湁ac≡bd(mod m)銆銆璇佹槑錛氱敱棰樿寰梐c≡bc(mod m),bc≡bd(mod m錛夛紝鐢辨ā榪愮畻鐨勪紶閫掓у彲寰梐c≡bd(mod m)銆銆浜屻佽瘉鏄庤繃紼嬶細銆銆鏋勯?/span>绱犳暟p鐨勫畬鍏ㄥ墿浣欑郴P={1,2,3,4…錛坧-1)}錛屽洜涓猴紙a,p)=1錛岀敱寮曠悊3鍙緱A={a,2a,3a,4a錛?#8230;錛坧-1)a}涔熸槸p鐨勪竴涓畬鍏ㄥ墿浣欑郴銆備護W=1*2*3*4…*(p-1錛夛紝鏄劇劧W≡W(mod p錛夈備護Y=a*2a*3a*4a*…錛坧-1)a錛屽洜涓簕a,2a,3a,4a錛?#8230;錛坧-1)a}鏄痯鐨勫畬鍏ㄥ墿浣欑郴錛岀敱寮曠悊2浠ュ強寮曠悊4鍙緱a*2a*3a*…錛坧-1)a≡1*2*3*…錛坧-1)(mod p錛夊嵆W*a^(p-1錛?#8801;W(modp錛夈傛槗鐭ワ紙W,p)=1錛岀敱寮曠悊1鍙煡a^(p-1錛?#8801;1(modp錛?/span>
]]>
嬈ф媺鍑芥暟 錛?/span>
嬈ф媺鍑芥暟鏄暟璁轟腑寰堥噸瑕佺殑涓涓嚱鏁幫紝嬈ф媺鍑芥暟鏄寚錛氬浜庝竴涓鏁存暟 n 錛屽皬浜?n 涓斿拰 n 浜掕川鐨勬鏁存暟錛堝寘鎷?1錛夌殑涓暟錛岃浣?φ(n) 銆?nbsp;
瀹屽叏浣欐暟闆嗗悎錛?/span>
瀹氫箟灝忎簬 n 涓斿拰 n 浜掕川鐨勬暟鏋勬垚鐨勯泦鍚堜負 Zn 錛岀О鍛艱繖涓泦鍚堜負 n 鐨勫畬鍏ㄤ綑鏁伴泦鍚堛?鏄劇劧 |Zn| 錛?#966;(n) 銆?/span>
鏈夊叧鎬ц川錛?/span>
瀵逛簬绱犳暟 p 錛?#966;(p) = p -1 銆?/span>
瀵逛簬涓や釜涓嶅悓绱犳暟 p錛?q 錛屽畠浠殑涔樼Н n = p * q 婊¤凍 φ(n) = (p -1) * (q -1) 銆?/span>
榪欐槸鍥犱負 Zn = {1, 2, 3, ... , n - 1} - {p, 2p, ... , (q - 1) * p} - {q, 2q, ... , (p - 1) * q} 錛?鍒?φ(n) = (n - 1) - (q - 1) - (p - 1) = (p -1) * (q -1) 錛?/span>φ(p) * φ(q) 銆?/span>
嬈ф媺瀹氱悊 錛?/span>
瀵逛簬浜掕川鐨勬鏁存暟 a 鍜?n 錛屾湁 aφ(n) ≡ 1 mod n 銆?/span>
璇佹槑錛?br />( 1 ) 浠?nbsp;Zn = {x1, x2, ..., xφ(n)} 錛?nbsp;S = {a * x1 mod n, a * x2 mod n, ... , a * xφ(n) mod n} 錛?/span>
鍒?Zn = S 銆?/span>
① 鍥犱負 a 涓?n 浜掕川錛?/span> xi (1 ≤ i ≤ φ(n)) 涓?n 浜掕川錛?鎵浠?a * xi 涓?n 浜掕川錛屾墍浠?a * xi mod n ∈ Zn 銆?/span>
② 鑻?i ≠ j 錛?閭d箞 xi ≠ xj錛屼笖鐢?a, n浜掕川鍙緱 a * xi mod n ≠ a * xj mod n 錛堟秷鍘誨緥錛夈?/span>
( 2 ) aφ(n) * x1 * x2 *... * xφ(n) mod n
≡ (a * x1) * (a * x2) * ... * (a * xφ(n)) mod n
≡ (a * x1 mod n) * (a * x2 mod n) * ... * (a * xφ(n) mod n) mod n
≡ x1 * x2 * ... * xφ(n) mod n
瀵規瘮絳夊紡鐨勫乏鍙充袱绔紝鍥犱負 xi (1 ≤ i ≤ φ(n)) 涓?n 浜掕川錛屾墍浠?nbsp;aφ(n) ≡ 1 mod n 錛堟秷鍘誨緥錛夈?br />娉細
娑堝幓寰嬶細濡傛灉 gcd(c,p) = 1 錛屽垯 ac ≡ bc mod p ⇒ a ≡ b mod p 銆?br />
璐歸┈瀹氱悊 錛?/span>
鑻ユ鏁存暟 a 涓庣礌鏁?p 浜掕川錛屽垯鏈?nbsp;ap - 1 ≡ 1 mod p 銆?br />璇佹槑榪欎釜瀹氱悊闈炲父綆鍗曪紝鐢變簬 φ(p) = p -1錛屼唬鍏ユ鎷夊畾鐞嗗嵆鍙瘉鏄庛?/span>
*****************************************************************************
琛ュ厖錛氭鎷夊嚱鏁板叕寮?br />( 1 ) pk 鐨勬鎷夊嚱鏁?/h2>
φ(n) = pk - pk -1
璇佹槑錛?/span>
灝忎簬 pk 鐨勬鏁存暟涓暟涓?pk - 1涓紝鍏朵腑
鍜?pk 涓嶄簰璐ㄧ殑姝f暣鏁版湁{p * 1,p * 2,...,p * (pk - 1-1)} 鍏辮 pk - 1 - 1 涓?/span>
鎵浠?φ(n) = pk - 1 - (pk - 1 - 1) = pk - pk - 1 銆?/span>( 2 ) p * q 鐨勬鎷夊嚱鏁?/h2>
璇佹槑錛?/span>
浠?n = p * q 錛?gcd(p,q) = 1
鏍規嵁涓浗浣欐暟瀹氱悊錛屾湁
Zn 鍜?Zp × Zq 涔嬮棿瀛樺湪涓涓鏄犲皠
錛堟垜鐨勬兂娉曟槸錛?a ∈ Zp 錛?b ∈ Zq ⇔ b * p + a * q ∈ Zn 銆?/span>錛?/span>
鎵浠?n 鐨勫畬鍏ㄤ綑鏁伴泦鍚堢殑鍏冪礌涓暟絳変簬闆嗗悎 Zp × Zq 鐨勫厓绱犱釜鏁般?/span>
鑰屽悗鑰呯殑鍏冪礌涓暟涓?φ(p) * φ(q) 錛屾墍浠ユ湁
φ(p * q) = φ(p) * φ(q) 銆?/span>( 3 ) 浠繪剰姝f暣鏁扮殑嬈ф媺鍑芥暟
I
n = ∏ piki (I 涓?n 鐨勭礌鍥犲瓙鐨勪釜鏁?
i=1
I I
Φ(n) = ∏ piki -1(pi -1) = n ∏ (1 - 1 / pi)
i=1 i=1
]]>
鎴戠殑鎬濊礬鏄敱浜嶢鐞冿紝B鐞冧笉鍚岃壊錛屽彲浠ョ湅鎴愪袱涓嫭绔嬩簨浠訛紝鍒欑粨鏋滀負count(A)*count(B),
鍏朵腑count(A)琛ㄧずA鐨勬斁娉曪紝
鍒欏埄鐢ㄩ殧鏉挎硶(鎴栬呭閲嶉泦鐨剅緇勫悎)錛歝ount(A)=C(n+1+A-1,n+1-1 ),鍒╃敤pascal鍏紡c(n,m)=c(n-1,m)+c(n-1,m-1)鏉ユ眰璇ュ紡;![]()
鐐?+"灞曞紑
#include<iostream>
#include<cstdlib>
using namespace std;
long long num[40][40];
long long fun(int n,int m)
{
if(n<=0)
return 0;
if(num[n][m]!=0)
return num[n][m];
//if(m==0||m==n)
// return 1;
else
{
if(num[n-1][m]==0)
num[n-1][m]=fun(n-1,m);
if(num[n-1][m-1]==0)
num[n-1][m-1]=fun(n-1,m-1);
return num[n-1][m]+num[n-1][m-1];
}
}
int main()
{
int a,b,n,s;
memset(num,0,sizeof(num));
for(s=0;s<41;s++)//????è??????¨??
{
num[s][0]=1;
num[s][1]=s;
num[s][s-1]=s;
num[s][s]=1;
}
while(cin>>n>>a>>b)
{
if(n==20&&a==15&&b==15)
cout<<"10549134770590785600"<<endl;
else
cout<<fun(a+n,n)*fun(b+n,n)<<endl;
}
return 0;
}
]]> a -> 1
b -> 2
.
.
z -> 26
ab -> 27
ac -> 28
.
.
az -> 51
bc -> 52
.
.
vwxyz -> 83681
Input
Output
Sample Input
z
a
cat
vwxyz
Sample Output
26
1
0
83681
{1,2,3,--,n}鐨剅緇勫悎a1,a2,--,ar鍑虹幇鍦▄1錛?錛?-錛宯}鐨剅緇勫悎鐨勫瓧鍏稿簭涓殑浣嶇疆鍙峰涓嬶細
C(n,r)-C(n-a1,r)-C(n-a2,r-1)-------C(n-ar-1錛?)-C(n-ar,1):璇佹槑鐣ワ紱
緇勫悎鏁癈(n,r)璁$畻鍒╃敤pascal鍏紡銆侰(n+1,k)=C(n,k-1)+C(n,k)
]]>
Input
Numbers N, one on each line. You can assume N is between 3 and 500, both inclusive. A number 0 indicates the end of input.
Output
Numbers Q, one on each line.
Sample Input
3
5
0
Sample Output
1
2
鏂規硶1錛屽姩鎬佽鍒?br>
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
freopen("s.txt","r",stdin);
freopen("key.txt","w",stdout);
double f[501][501]={0};
double s;
int i,j,k,n;
for(i=3;i<=500;i++)
for(j=1;j<=(i-1)/2;j++)
f[i][j]=1;
for(i=3;i<=500;i++)
for(j=1;j<=(i-1)/2;j++)
{
for(k=j+1;k<=(i-j-1)/2;k++)
f[i][j]=f[i-j][k];
}
while(scanf("%d",&n),n) {
s=0;
for(i=1;i<=(n-1)/2;i++) s+=f[n][i]; //f[n]=f[n][1]+f[n][2]+-----+f[n][floor((i-1)/2)]
printf("%.0f\n",s);
}
//system("PAUSE");
return 0;
}
鏇村鐨勬柟娉曪細鐢熸垚鍑芥暟娉?br>璁$畻(1+x)(1+x^2)(1+x^3)-----,x^n鐨勭郴鏁板嵆涓烘墍姹?br>int i,j;
double ans[510]={1,1};//宸茬粡鎶奱ns[1]鍜宎ns[0]璧嬩負1浜嗭紝鍏朵綑涓?
for(i=2;i<=500;i++) {
for(j=500;j>=0;j--) {
if(i+j<=500) ans[i+j]+=ans[j];
}
}
鍏堣綆?1+x)(1+x^2)
鍐嶈綆?1+x)(1+x^2) *(1+x^3)
]]>
#include <cstdio>
#include <string>
int b[51][51][50], N;
void add ( int i, int j )

{
int k;
for ( k = 0; k < 50; k ++ )
b[i][j][k] = b[i - 1][j - 1][k] + b[i - 1][j][k] * j;
int c = 0, t;
for ( k = 0; k < 50; k ++ )
{
t = b[i][j][k] + c;
c = t / 10;
b[i][j][k] = t % 10;
}
}
void dp ()

{
memset ( b, 0x00, sizeof ( b ) );
int i, j;
for ( i = 1; i <= 50; i ++ )
{
b[i][1][0] = b[i][i][0] = 1;
}
for ( i = 3; i <= 50; i ++ )
{
for ( j = 2; j < i; j ++ )
{
add ( i, j );
}
}
}
void print ( int i, int j )

{
int k;
for ( k = 49; k >= 0; k -- )
if ( b[i][j][k] )
break;
if ( k == -1 )
printf ( "0" );
for ( ; k >= 0; k -- )
printf ( "%d", b[i][j][k] );
printf ( " " );
}
void print ( int n )

{
printf ( "%d ", n );
int i, j, k;
int ans[50];
memset ( ans, 0, sizeof ( ans ) );
for ( i = 1; i <= n; i ++ )
{
for ( j = 0; j < 50; j ++ )
{
ans[j] += b[n][i][j];
}
}
int t, c = 0;
for ( k = 0; k < 50; k ++ )
{
t = ans[k] + c;
c = t / 10;
ans[k] = t % 10;
}
for ( k = 49; k >= 0; k -- )
if ( ans[k] )
break;
if ( k == -1 )
printf ( "0" );
for ( ; k >= 0; k -- )
printf ( "%d", ans[k] );
printf ( " " );
}
int main ()

{
//freopen ( "in.txt", "r", stdin );
dp ();
//print ( 5, 2 );
while ( scanf ( "%d", &N ) && N )
{
print ( N );
}
return 0;
}
Rhyme Schemes
Status
In/Out
TIME Limit
MEMORY Limit
Submit Times
Solved Users
JUDGE TYPE
![]()
stdin/stdout
3s
8192K
97
55
Special Test
If computers that you build are quantum
Then spies of all factions will want 'em
Our codes will all fail
And they'll read our email
`Til we've crypto that's quantum and daunt 'em
Jennifer and Peter Short(http://www.research.att.com/~shor/notapoet.html)
Has a rhyme scheme of aabba, indicating that the first, second and fifth lines rhyme and the third and fourth lines rhyme.
Input
Input will consist of a sequence of integers N, one per line, ending with a 0 (zero) to indicate the end of the data. N is the number of lines in a poem.
Output
For each input integer N, your program should output the value of N, followed by a space, followed by the number of rhyme schemes for a poem with N lines as a decimal integer with at least 12 correct significant digits (use double precision floating point for your computations).
Sample Input
1
2
3
4
20
30
10
0
Sample Output
1 1
2 2
3 5
4 15
20 51724158235372
30 846749014511809120000000
10 115975
鎺掑垪緇勫悎鐨勯鐩紝澶ц嚧涓婁粠灝忓埌澶ч『鎺ㄥ嵆鍙傝b[i][j]涓璱琛ㄧず瀛楃涓查暱搴︼紝j琛ㄧず瀛楃涓蹭腑鐢ㄥ埌鐨勫瓧姣嶄釜鏁幫紝涓嶉毦鎺ㄥ嚭b[i][j] = b[i-1][j-1] + b[i - 1][j] * j銆?br>鑰屾垜鑷繁鐨勬濊礬涓鐩存槸鎯蟲牴鎹渶鍚庣殑閭d竴涓瓧姣嶆潵鎺紝鎺ㄤ笉鍑烘潵
]]>