![]() |
|
|
#2069 | |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
Quote:
Code:
sieve_of_eratosthenes(x) = d=vector((x-1),n,n+1);index=1;p=2;for(y=1,#d,if(d[y]!=0,index=y;p=d[y]);if(p^2>x,break(2));forstep(i=index+p,#d,p,if(d[i]!=0,d[i]=0))) The main difference to what I did here and the other is that the numbers were represented poorly in the indexes of a vector. Last fiddled with by science_man_88 on 2010-12-14 at 23:07 |
|
|
|
|
|
|
#2070 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
Last fiddled with by science_man_88 on 2010-12-14 at 23:43 |
|
|
|
|
|
|
#2071 |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
not sure how to turn it into Atkin or Sundaram
|
|
|
|
|
|
#2072 |
|
Aug 2006
3·1,993 Posts |
|
|
|
|
|
|
#2073 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
does your semiprime detector have anything to do with: Code:
fa = factor(N);
isprime( fa[,1] )
|
|
|
|
|
|
|
#2074 | |
|
Aug 2006
3×1,993 Posts |
Quote:
Right now it looks like this: Code:
long
issemiprime(GEN n)
{
if (typ(n) != t_INT)
pari_err(arither1, "issemiprime");
if (signe(n) <= 0)
return 0;
ulong nn = itou_or_0(n);
if (nn)
return uissemiprime(nn);
pari_sp ltop = avma;
if (!mpodd(n)) {
long ret = mod4(n) && isprime(shifti(n, -1));
avma = ltop;
return ret;
}
long p = 0;
byteptr primepointer = diffptr;
NEXT_PRIME_VIADIFF(p, primepointer); // Skip 2
for (;;)
{
NEXT_PRIME_VIADIFF(p, primepointer);
if (p > 997) // What is a good breakpoint here?
break;
if (dvdis(n, p)) // "1 if p divides n and 0 otherwise"
{
long ret = isprime(diviuexact(n, p));
avma = ltop;
return ret;
}
}
if (isprime(n))
return 0;
GEN fac = Z_factor_until(n, shifti(n, -1)); // Find a nontrivial factor -- returns just the factored part
GEN expo = gel(fac, 2);
GEN pr = gel(fac, 1);
long len = glength(expo);
if (len > 2) {
avma = ltop;
return 0;
}
if (len == 2) {
if (cmpis(gel(expo, 1), 1) > 0 || cmpis(gel(expo, 2), 1) > 0) {
avma = ltop;
return 0;
}
GEN p = gel(pr, 1);
GEN q = gel(pr, 2);
long ret = !cmpii(mulii(p, q), n) && isprime(p) && isprime(q);
avma = ltop;
return ret;
}
if (len == 1) {
long e = itos(gel(expo, 1));
if (e != 2) {
avma = ltop;
return 0;
}
GEN p = gel(pr, 1);
long ret = !cmpii(sqri(p), n) && isprime(p);
avma = ltop;
return ret;
}
pari_err(talker, "Z_factor_until returned an unexpected value %Ps at n = %Ps, exiting...", fac, n);
avma = ltop;
return NEVER_USED;
}
|
|
|
|
|
|
|
#2075 |
|
"Forget I exist"
Jul 2009
Dumbassville
100000110000002 Posts |
Code:
(11:17)>v=vector(100,n,20) %359 = [20, 20, 20, 20, 20, 20, (11:18)>v=vector(100,n,n) %360 = [1, 2, 3, 4, 5, 6, 7, 8, (11:18)>v=vector(#v-1,n,v[n]) %361 = [1, 2, 3, 4, 5, 6, 7, 8, (11:18)>v=vector(#v-1,n,v[n+1]) %362 = [2, 3, 4, 5, 6, 7, 8, 9, Code:
(11:22)>vecsort(v) %377 = [16, 17, 18, 19 Last fiddled with by science_man_88 on 2010-12-15 at 15:22 |
|
|
|
|
|
#2076 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
nice I found a faster way to reverse a vector lol, might have to update reverse with this one lol:
Code:
v=vector(#v,n,v[#v-(n-1)]) |
|
|
|
|
|
#2077 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
Code:
c=Vecsmall("hello");c=vector(#c,n,c[#c-(n-1)]);print(Strchr(c))
Last fiddled with by science_man_88 on 2010-12-15 at 15:51 |
|
|
|
|
|
|
#2078 |
|
Jun 2003
13DF16 Posts |
|
|
|
|
|
|
#2079 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
only thing I've been able to accomplish is throwing out every index I wanted to use and left with the one I wanted off.
never mind I got one half of those 2 to work but how do i do the other side ? Code:
c=vecextract(c,vector(#c-1,n,n)) Code:
c=vecextract(c,vector(#c-1,n,n+1)) Last fiddled with by science_man_88 on 2010-12-15 at 16:18 |
|
|
|
![]() |
| Thread Tools | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why do I sometimes see all the <> formatting commands when I quote or edit? | cheesehead | Forum Feedback | 3 | 2013-05-25 12:56 |
| Passing commands to PARI on Windows | James Heinrich | Software | 2 | 2012-05-13 19:19 |
| Ubiquity commands | Mini-Geek | Aliquot Sequences | 1 | 2009-09-22 19:33 |
| 64-bit Pari? | CRGreathouse | Software | 2 | 2009-03-13 04:22 |
| Are these commands correct? | jasong | Linux | 2 | 2007-10-18 23:40 |