Re: The Math Help Topic
Posted: Thu Jan 27, 2011 10:39 pm
My course is focusing on analysis mainly so far, yours seems more interesting... it's gonna change next year though (if I make it to the Higher Maths department of my faculty)
Hahahahah, p0wnedDesLife wrote:Fuck you, it's been 13500 seconds here already. xD
Code: Select all
proc (n)
local btor, nr, p, r;
options remember, system,
‘Copyright 1993 by Waterloo Maple Software‘;
if not type(n,integer) then
if type(n,numeric) then
ERROR(‘argument must be an integer‘)
else
RETURN(’isprime(n)’)
;
if n
<
2 then
false
elif has(‘isprime/w‘,n) then
true
elif igcd(2305567963945518424753102147331756070,n)
<>
1 then
false
elif n
<
10201 then
true
elif igcd(84969694892334181105323399091873499659260625866489327366
1154542634220389327076939090906947730950913750978691711866802886149933382
5097682386722983737962963066757674131126736578936440788157186969893730633
1130664786204486249492573240226273954373636390387526081667586612559568346
3069722044751229884822222855006268378634251996022599630131594564447006472
0696621750477244528915927867113,n)
<>
1 then
false
elif n
<
1018081 then
true
else nr := igcd(408410100000,n-1);
nr := igcd(nr^ 5,n-1);
r := iquo(n-1,nr);
btor := modp(power(2,r),n);
if ‘isprime/cyclotest‘(n,btor,2,r) = false
or irem(nr,3) = 0 and ‘isprime/cyclotest‘(n,btor,3,r) = false
or irem(nr,5) = 0 and ‘isprime/cyclotest‘(n,btor,5,r) = false
or irem(nr,7) = 0 and ‘isprime/cyclotest‘(n,btor,7,r) = false then
RETURN(false)
;
for p from 3 while (numtheory[jacobi])(p^ 2-4,n)
<>
-1 do od;
evalb(‘isprime/TraceModQF‘(p,n+1,n) = [2, p])
fi
endWould look way better with tabs and beter use of new lines, now it's just unreadableDesLife wrote:Fuck, that's fast. But his code is not readable at all ahahah. But it's 69000 times faster than mine so that's worth it.![]()
It seems that this is isprime()'s code :
Enjoy.Code: Select all
proc (n) local btor, nr, p, r; options remember, system, ‘Copyright 1993 by Waterloo Maple Software‘; if not type(n,integer) then if type(n,numeric) then ERROR(‘argument must be an integer‘) else RETURN(’isprime(n)’) ; if n < 2 then false elif has(‘isprime/w‘,n) then true elif igcd(2305567963945518424753102147331756070,n) <> 1 then false elif n < 10201 then true elif igcd(84969694892334181105323399091873499659260625866489327366 1154542634220389327076939090906947730950913750978691711866802886149933382 5097682386722983737962963066757674131126736578936440788157186969893730633 1130664786204486249492573240226273954373636390387526081667586612559568346 3069722044751229884822222855006268378634251996022599630131594564447006472 0696621750477244528915927867113,n) <> 1 then false elif n < 1018081 then true else nr := igcd(408410100000,n-1); nr := igcd(nr^ 5,n-1); r := iquo(n-1,nr); btor := modp(power(2,r),n); if ‘isprime/cyclotest‘(n,btor,2,r) = false or irem(nr,3) = 0 and ‘isprime/cyclotest‘(n,btor,3,r) = false or irem(nr,5) = 0 and ‘isprime/cyclotest‘(n,btor,5,r) = false or irem(nr,7) = 0 and ‘isprime/cyclotest‘(n,btor,7,r) = false then RETURN(false) ; for p from 3 while (numtheory[jacobi])(p^ 2-4,n) <> -1 do od; evalb(‘isprime/TraceModQF‘(p,n+1,n) = [2, p]) fi end
That's not soon. You have disappointed me...DesLife wrote:6 months.PluMGMK wrote:Ah, but how soon is soon?DesLife wrote:Plum : soon.
Code: Select all
int main()
{
double diff;
clock_t start = clock();
bool* IsPrime = new bool[SIZE];
for (unsigned long i=0; i<SIZE; i++) IsPrime[i] = true;
IsPrime[0] = false; IsPrime[1] = false; IsPrime[2] = true;
//Sieve of Eratosthenes
for (unsigned long i = 2; i < sqrt((double)SIZE); i++)
{
if (IsPrime[i])
{
unsigned long j = 2;
while (i*j < SIZE)
{
IsPrime[i*j] = false;
++j;
}
}
}
long count = 0;
for (unsigned long i = 0; i < SIZE; i++)
if(IsPrime[i]) ++count;
diff = ( clock() - start ) / (double)CLOCKS_PER_SEC;
cout << count << "\nTime taken: " << diff << " seconds.\n" << endl;
delete[] IsPrime;
return 0;
}