瀵逛簬緇欏畾鐨勪竴涓礌鏁?p 錛?φ(p) = p -1銆傚垯瀵逛簬姝f暣鏁?n = pk 錛?/p>
φ(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>
鍋囪 p, q鏄袱涓簰璐ㄧ殑姝f暣鏁幫紝鍒?p * q 鐨勬鎷夊嚱鏁頒負
φ(p * q) = φ(p) * φ(q) 錛?gcd(p, q) = 1 銆?/p>
璇佹槑錛?/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>
浠繪剰涓涓暣鏁?n 閮藉彲浠ヨ〃紺轟負鍏剁礌鍥犲瓙鐨勪箻縐負錛?/p>
I
n = ∏ piki (I 涓?n 鐨勭礌鍥犲瓙鐨勪釜鏁?
i=1
鏍規嵁鍓嶉潰涓や釜緇撹錛屽緢瀹規槗寰楀嚭瀹冪殑嬈ф媺鍑芥暟涓猴細
I I
Φ(n) = ∏ piki -1(pi -1) = n ∏ (1 - 1 / pi)
i=1 i=1
瀵逛簬浠繪剰 n > 2錛?span style="line-height: 24px; font-weight: bold; ">2 | Φ(n) ,鍥犱負蹇呭瓨鍦?nbsp; pi -1 鏄伓鏁般?/p>
鍏跺疄灝辨槸鎶夾涓孩鐞冿紝B涓鐞冨垎鎴恘+1鍫嗭紙闄鍫嗗榪樻湁涓鍫嗗氨鏄病鏈夋斁鍏ョ洅涓殑錛夈?br>鎬濊礬寰堥噸瑕侊紝
鎴戠殑鎬濊礬鏄敱浜嶢鐞冿紝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)鏉ユ眰璇ュ紡;
榪樻湁涓涓敞鎰忕偣褰撲笖浠呭綋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:
a -> 1 b -> 2 . . z -> 26 ab -> 27 ac -> 28 . . az -> 51 bc -> 52 . . vwxyz -> 83681
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.
z a cat vwxyz
26 1 0 83681
鍒╃敤緇勫悎鏁板瀹氱悊
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.
3 5 0
1 2鏂規硶1錛屽姩鎬佽鍒?br>
Status | In/Out | TIME Limit | MEMORY Limit | Submit Times | Solved Users | JUDGE TYPE |
---|---|---|---|---|---|---|
![]() |
stdin/stdout | 3s | 8192K | 97 | 55 | Special Test |
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
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.
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.
1 2 3 4 20 30 10 0
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竴涓瓧姣嶆潵鎺紝鎺ㄤ笉鍑烘潵