3. if n = 1 then STOP
4. if n is odd then n <-- 3n+1
5. else n <-- n/2
问题很明白,之前在hdu上也做了Q经验还是没有哇。WA了好多好多次?br />1w的数据很弱,直接暴力当然能过?br />不过100W׃行了。记忆化搜烦DP是个好办?br />我最之前的做法就是这个,效果q算不错?br />
求出所有的值后是区间求最大gQ有RMQ法Q线D|(wi){都行。不q,我都不会(x)呀Q!Q!Q!Q!
朗讯的时候就做了个区间最值的问题Q当时朴素算法一直WAQjh辉神 qsort()一下,从前往后给AC了。YQYQ?br />
最后还是就是细节问题了Q像输出s,t。有可能s>t,输出却是要按照输入顺序输出!晕,pPDQ了一天?br />ȝQ?br /> l节问题要注意!多想惛_他算法,水题不水呀?br />
额,代码q是没有自己风格啊。这些个函数名还是那么难取呢?br />
题目大意Q给定一个大整数Q这个数是两个素数的乘积Q然后给定一个数LQ如果这两个素数中有一个比L,p出BADQ不然输出GOOD
baby_step gaint_step 法基本思想:
对于一个n个元素的循环(n很大很大) 先算出前面m?baby_step) 然后以m?gaint_step)大蟩 那么跳了n/m步以?一定能跛_前面出来的m步里?q样旉复杂度就降到O(m+n/m) I间复杂度ؓ(f)O(m)
对于计算a^x==b(mod n)中的x
先计b,b*a,b*a^2,...b*a^m 然后计算1Qa^m,a^2m,a^3m,... 那么l过i?是Ca^(i*m)的时?发现它等于b*a^j 那么x=i*m-j
一般m定ؓ(f)sqrt(n)q时空(q且q样旉复杂度最低) 查找用hash 事实证明map是非常慢?/p>
//更新
l过AekdyCoin盖世牛的检?我那个能在poj上跑的程序在hdu上先MLE 然后TLE 然后CE 然后RE 然后WA 千辛万苦 最后蟩qPE 变成AC?/p>
原因:动态链表hash跑太?以后要改成前向星?/p>
//l箋更新
l过AekdyCoin教导 发现q个法当a和n不互质的时候会(x)?因ؓ(f)没有逆元 i*m-j不能随便?/p>
于是q夜开发不互质法如下
设某质数p在a里的指数是ap 在n里面是np 在b里面是bp
那么当x很大 ap*x必然大于np q个时候bp必须不小于np 光命题也成立
同时 n里面的p全部除掉 剩下的由于和p互质 所以左边aQb可不必除 反正最后a^x-b一定整除n
所?先判断a和n的公p因数里面 有没有b比n的 若小必死 否则直接n除的和a互质再做完破
注意到每个质数的指数肯定不超q?0 那么当x大于40以上Ҏ(gu)必然成立 当x的时?虽然l证明也可以化ؓ(f)abn互质情况 但是不如直接验证 所以不了
分析:N蛙蟩了k?那么有(x+mk)-(y+nk)=p*L.
即x-y+(m-n)k=p*L,?m-n)*k≡(y-x) (mod L).
q个U性同余方E有解当且仅?span>gcd(m-n,L)|(y-x).
令a=m-n,b=L,c=y-x.用扩展欧几里得解方程ax+by=c.
可以求出原方E的一个解.如何求最正整数解呢?
假设我们已经得到一个x0,令d=gcd(m-n,L),
那么所有解可以表示为x=x0+k*L/d.
设L'=L/d.
Xmin=(x0 mod L'+L') mod L'.
WA两次Q?MsQ囧Q还有一ơ编译错误!Q!
ȝQ代码,q是得天天写Q三日不l手生。自己多xQ多思考思考才能提升能力哈?/p>
不要Lȝ别h的题解,要有自己的思\哈?/p>
数论Q还得l看Ql学。要吃透才行?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.