3. if n = 1 then STOP
4. if n is odd then n <-- 3n+1
5. else n <-- n/2
闂寰堟槑鐧斤紝涔嬪墠鍦╤du涓婁篃鍋氫簡(jiǎn)錛岀粡楠岃繕鏄病鏈夊搰銆俉A浜?jiǎn)濂藉濂藉娆°?br />1w鐨勬暟鎹緢寮憋紝鐩存帴鏆村姏褰撶劧鑳借繃銆?br />涓嶈繃100W灝變笉琛屼簡(jiǎn)銆傝蹇嗗寲鎼滅儲(chǔ)DP鏄釜濂藉姙娉?br />鎴戞渶涔嬪墠鐨勫仛娉曞氨鏄繖涓紝鏁堟灉榪樼畻涓嶉敊銆?br />
姹傚嚭鎵鏈夌殑鍊煎悗灝辨槸鍖洪棿姹傛渶澶у間簡(jiǎn)錛屾湁RMQ綆楁硶錛岀嚎孌墊爲(wèi)絳夐兘琛屻備笉榪囷紝鎴戦兘涓嶄細(xì)鍛錛侊紒錛侊紒錛侊紒錛侊紒
鏈楄鐨勬椂鍊欏氨鍋氫簡(jiǎn)涓尯闂存渶鍊肩殑闂錛屽綋鏃舵湸绱犵畻娉曚竴鐩碬A錛宩h杈夌 qsort()涓涓嬶紝浠庡墠寰鍚庣粰AC浜?jiǎn)銆傦脊錛脊錛?br />
鏈鍚庤繕鏄氨鏄粏鑺傞棶棰樹簡(jiǎn)錛屽儚杈撳嚭锝擄紝锝斻傛湁鍙兘锝擄紴锝旓紝杈撳嚭鍗存槸瑕佹寜鐓ц緭鍏ラ『搴忚緭鍑猴紒鏅曪紝灝辮繖鏍鳳擠錛′簡(jiǎn)涓澶┿?br />鎬葷粨錛?br /> 緇嗚妭闂瑕佹敞鎰忥紒澶氭兂鎯沖叾浠栫畻娉曪紝姘撮涓嶆按鍛銆?br />
棰濓紝浠g爜榪樻槸娌℃湁鑷繁椋庢牸鍟娿傝繖浜涗釜鍑芥暟鍚嶈繕鏄偅涔堥毦鍙栧憿銆?br />
棰樼洰澶ф剰錛氱粰瀹氫竴涓ぇ鏁存暟錛岃繖涓暟鏄袱涓礌鏁扮殑涔樼Н錛岀劧鍚庣粰瀹氫竴涓暟L錛屽鏋滆繖涓や釜绱犳暟涓湁涓涓瘮L灝忥紝灝辮緭鍑築AD錛涗笉鐒惰緭鍑篏OOD
baby_step gaint_step 綆楁硶鍩烘湰鎬濇兂:
瀵逛簬涓涓猲涓厓绱犵殑寰幆(n寰堝ぇ寰堝ぇ) 鍏堢畻鍑哄墠闈姝?baby_step) 鐒跺悗浠涓鴻法搴?gaint_step)澶ц煩 閭d箞璺充簡(jiǎn)n/m姝ヤ互鍚?涓瀹氳兘璺沖埌鍓嶉潰綆楀嚭鏉ョ殑m姝ラ噷闈?榪欐牱鏃墮棿澶嶆潅搴﹀氨闄嶅埌O(m+n/m) 絀洪棿澶嶆潅搴︿負(fù)O(m)
瀵逛簬璁$畻a^x==b(mod n)涓殑x
鍏堣綆梑,b*a,b*a^2,...b*a^m 鐒跺悗璁$畻1錛宎^m,a^2m,a^3m,... 閭d箞緇忚繃i姝?灝辨槸鍒頒簡(jiǎn)a^(i*m)鐨勬椂鍊?鍙戠幇瀹冪瓑浜巄*a^j 閭d箞x=i*m-j
涓鑸琺瀹氫負(fù)sqrt(n)騫寵 鏃剁┖(騫朵笖榪欐牱鏃墮棿澶嶆潅搴︽渶浣庯級(jí) 鏌ユ壘鐢╤ash 浜嬪疄璇佹槑map鏄潪甯告參鐨?/p>
//鏇存柊
緇忚繃AekdyCoin鐩栦笘紲炵墰鐨勬楠?鎴戦偅涓兘鍦╬oj涓婅窇鐨勭▼搴忓湪hdu涓婂厛MLE 鐒跺悗TLE 鐒跺悗CE 鐒跺悗RE 鐒跺悗WA 鍗冭緵涓囪嫤 鏈鍚庤煩榪嘝E 鍙樻垚AC浜?/p>
鍘熷洜:鍔ㄦ侀摼琛╤ash璺戝お鎱?浠ュ悗瑕佹敼鎴愬墠鍚戞槦浜?/p>
//緇х畫鏇存柊
緇忚繃AekdyCoin鏁欏 鍙戠幇榪欎釜綆楁硶褰揳鍜宯涓嶄簰璐ㄧ殑鏃跺欎細(xì)姝?鍥犱負(fù)娌℃湁閫嗗厓 i*m-j涓嶈兘闅忎究鍑?/p>
浜庢槸榪炲寮鍙戜笉浜掕川綆楁硶濡備笅
璁炬煇璐ㄦ暟p鍦╝閲岀殑鎸囨暟鏄痑p 鍦╪閲岄潰鏄痭p 鍦╞閲岄潰鏄痓p
閭d箞褰搙寰堝ぇ ap*x蹇呯劧澶т簬np 榪欎釜鏃跺檅p蹇呴』涓嶅皬浜巒p 鍏墮嗗懡棰樹篃鎴愮珛
鍚屾椂 灝唍閲岄潰鐨刾鍏ㄩ儴闄ゆ帀 鍓╀笅鐨勭敱浜庡拰p浜掕川 鎵浠ュ乏杈筧錛宐鍙笉蹇呴櫎 鍙嶆鏈鍚巃^x-b涓瀹氭暣闄
鎵浠?鍏堝垽鏂璦鍜宯鐨勫叕鍏辮川鍥犳暟閲岄潰 鏈夋病鏈塨姣攏灝忕殑 鑻ュ皬蹇呮 鍚﹀垯鐩存帴灝唍闄ょ殑鍜宎浜掕川鍐嶅仛瀹岀牬
娉ㄦ剰鍒版瘡涓川鏁扮殑鎸囨暟鑲畾涓嶈秴榪?0 閭d箞褰搙澶т簬40浠ヤ笂鏂規(guī)硶蹇呯劧鎴愮珛 褰搙灝忕殑鏃跺?铏界劧緇忚瘉鏄庝篃鍙互鍖栦負(fù)abn浜掕川鎯呭喌 浣嗘槸涓嶅鐩存帴楠岃瘉 鎵浠ヤ笉綆′簡(jiǎn)
鍒嗘瀽:璁鵑潚铔欒煩浜?jiǎn)k嬈?閭d箞灝辨湁(x+mk)-(y+nk)=p*L.
鍗硏-y+(m-n)k=p*L,鍗?m-n)*k≡(y-x) (mod L).
榪欎釜綰挎у悓浣欐柟紼嬫湁瑙e綋涓斾粎褰?span>gcd(m-n,L)|(y-x).
浠=m-n,b=L,c=y-x.鐢ㄦ墿灞曟鍑犻噷寰楄В鏂圭▼ax+by=c.
鍙互姹傚嚭鍘熸柟紼嬬殑涓涓В.濡備綍姹傛渶灝忔鏁存暟瑙e憿?
鍋囪鎴戜滑宸茬粡寰楀埌涓涓獂0,浠=gcd(m-n,L),
閭d箞鎵鏈夎В鍙互琛ㄧず涓簒=x0+k*L/d.
璁綥'=L/d.
Xmin=(x0 mod L'+L') mod L'.
WA涓ゆ錛?Ms錛屽洤錛岃繕鏈変竴嬈$紪璇戦敊璇紒錛侊紒
鎬葷粨錛氫唬鐮侊紝榪樻槸寰楀ぉ澶╁啓錛屼笁鏃ヤ笉緇冩墜鐢熴傝嚜宸卞鎯蟲兂錛屽鎬濊冩濊冩墠鑳芥彁鍗囪兘鍔涘搱銆?/p>
涓嶈鎬繪槸鍘葷湅鍒漢鐨勯瑙o紝瑕佹湁鑷繁鐨勬濊礬鍝堛?/p>
鏁拌錛岃繕寰楃戶緇湅錛岀戶緇銆傝鍚冮忔墠琛屻?br />
The easiest way to make the problem statement unusual is to omit it. This is an extremely convenient approach — you don’t have to maintain the statement in two languages or to worry that it might turn out to be ambiguous or too long or too scary. 690 people solved this problem, so evidently we can omit statements even in regular rounds :-)
As for the problem itself, it required to sum the first number and the reverse of the second number.
They say it’s better to see once than to hear ten times or to read a hundred times. In this problem we decided to check this and to replace the traditional textual statement with a single image. Same as in the previous problem, it did well — at least 645 participants recognized star numbers (sequence http://oeis.org/A003154 in OEIS), the numbers of balls needed to form a six-pointed start of certain size. After this one had only to code the formula — Sn = 6n(n−1) + 1.
What does one do if the statement is unknown and the only source of information about the problem is the checker? Right — you just try all possible functions which convert 5 input values into 3 output values and see which of them fits :-)
This problem finally has a statement! The trick is, it’s encoded. We decided to be kind to you and to use the simplest cipher possible — Caesar cipher (each letter is shifted the same number of positions in the alphabet). By a long stretch of imagination one could break the cipher by hand — observe frequent letters and short words, deduce possible values of shift and verify it against the rest of the message. A lazier one could Goog
le for a tool like this one and get the decoded version semi-automatically.
After cracking the statement the rest was almost easy — you had to find a prime whose reverse is a prime different from the original one (sequence http://oeis.org/A006567). 11184-th such number equals 999983, so one could do a brute-force check of all numbers in row.
A special contest written by me and no special programming language? Impossible! I pulled myself up and made only 25% of all problems esoteric — that’s two. There really should be three but the third interpreter refused to cooperate. Maybe next time…
What can one do if all he knows about the language is its compiler? Just run any code and see what the compiler says. In this case the compiler said “DO YOU EXPECT ME TO FIGURE THIS OUT?”, and Google should tell you immediately that the language in question is INTERCAL. The problem simplifies to figure out the dialect used and how to output “INTERCAL” in it.
In Codeforces round #96 I gave a problem 133C - Turing Tape which explained the mechanism of string output in INTERCAL and asked to write a program which converted a string into an array of numbers which would print this string. Combine this knowledge with Hello, World! example and you get the program you need. Actually, that’s what I did to write the reference solution.
PLEASE DO ,1 <- #8 DO ,1 SUB #1 <- #110 PLEASE DO ,1 SUB #2 <- #32 DO ,1 SUB #3 <- #72 DO ,1 SUB #4 <- #136 DO ,1 SUB #5 <- #88 DO ,1 SUB #6 <- #136 DO ,1 SUB #7 <- #64 DO ,1 SUB #8 <- #80 PLEASE READ OUT ,1 PLEASE GIVE UP
The second esoteric problem had a Chef program as the statement. You had only to figure out what it does and do it in any regular language. It turns out that this program reads N followed by N numbers $a_1, a_2, …, a_N$ and calculated the sum i * ai.
This one was much harder to guess but much easier to code. First two numbers were the start of a Fibonacci-like sequence, and the third one was the index of the required number in this sequence.