|
|
I have "Time Limit" in test #4. Can you help me. [code deleted] Edited by moderator 01.06.2006 16:14 Of course you got TLE... you algo is O(n)and certainly will get TLE Real Help! First of all we must diminish number of candidate to optimal. MathHelp:if (A^k)%N==1 => fi(N)%k==0 where fi(N)-Eiler function of N Try find in Internet effective algorith for fi(N). we can see that number of candidates diminished from 1000000000 to 2*sqrt(1000000000)~64000 Also if Nod(A,N)>0 print 0. Final trick is using divide recursion when calculating (A^K)%N=>O(log K)-time and don't forget use __int64 when form A*B Edited by author 17.08.2007 02:26 Good point svr! :) But number of ways diminishes to amount of divisors of phi(N) which is way less than 64000, and it's enough to factorize phi(N) itself to get them all recursively. Edited by author 20.08.2008 17:46 NOD is russian for GCD :-) Give some some tests ,please Edited by author 07.07.2012 22:30 Please help. What is the input? I have "Wrong answer" in test 4, but I don`t understand where my mistake.Can you help me? Please, show me test 4 or something like. Edited by author 18.08.2011 23:48 Edited by author 19.08.2011 15:36 131313213 453535 Result: 14860 by both way (O(ln n) and O(n) ) result is 112562728 453535^14860 (131313213) !=1 !!! Help me, what algorithms against a limit time the Test №4 operates??? PLEASSSSSSSSS!!!! A^X=1 mod N; if X is even, we can find quickly A^(X/2) (watch problem 1134). If X is odd, we have to solve A*A^(X-1)/2=1 mod N. Therefore we have to find inverse number for A. And so on. Well, now, it's a fast quick recursion checking two cases... Gonna check that soon... |
|
|