![]() |
|
|
#2168 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
thanks for the tip I never quite figured it out I asked because i was seeing something that I sent to prime95 as weird, now I don't as much but if you look (2^mersenne1[n]-1)%n seems to be a mersenne number a lot if mersenne1 is the mersenne prime exponents. in fact it looks like 35/40 have this property in the first 100 prime numbers if you do 2^(prime(n))-1 over there index into the primes it seems about 49% of the first 100 work out.
|
|
|
|
|
|
#2169 |
|
Aug 2006
3·1,993 Posts |
ispower(n) checks if n is a nontrivial power. ispower(n,k) checks if n is a k-th power. ispower(n,,&b) checks if n is a nontrivial power and, if so, stores the base in b. ispower(n,k,&b) checks if n is a k-th power and, if so, stores the base in b.
|
|
|
|
|
|
#2170 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
it should be able to check if n is a power of b.
|
|
|
|
|
|
#2171 |
|
Jun 2003
5,087 Posts |
|
|
|
|
|
|
#2172 |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
or just:
Code:
(18:55)>a=0;for(n=1,#mersenne1,if(valuation(((2^mersenne1[n]-1)%n)+1,2)!=0,a=a+1));return(a) %51 = 35 Last fiddled with by science_man_88 on 2011-02-10 at 22:59 |
|
|
|
|
|
#2173 |
|
Aug 2006
3×1,993 Posts |
I've needed that too, at least in the case of powers of two. axn's solution is good. For a faster method, I implemented
Code:
long
ispow2(GEN n)
{
if (typ(n) != t_INT)
pari_err(arither1, "ispow2");
if (signe(n) < 1)
return 0;
pari_sp ltop = avma;
GEN xp = int_LSW(n);
long lx = lgefint(n);
ulong u = *xp;
long i = 3;
for (; i < lx; ++i)
{
if (u != 0)
{
avma = ltop;
return 0;
}
xp = int_nextW(xp);
u = *xp;
}
avma = ltop;
return !(u & (u-1));
}
Of course, this is comparing apples and oranges. The internal form of axn's algorithm (when appropriately optimized) is Code:
long
ispow2(GEN n)
{
if (typ(n) != t_INT)
pari_err(arither1, "ispow2");
if (signe(n) < 1)
return 0;
pari_sp ltop = avma;
long ret = expi(n) == vali(n);
avma = ltop;
return ret;
}
Last fiddled with by CRGreathouse on 2011-02-11 at 00:01 |
|
|
|
|
|
#2174 | |
|
Aug 2006
3·1,993 Posts |
Quote:
Code:
sum(n=1,#mersenne1,((2^mersenne1[n]-1)%n)%2) |
|
|
|
|
|
|
#2175 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
Code:
a=0;for(n=1,#mersenne1,if(2^valuation((((2^mersenne1[n])-1)%n)+1,2)==(((2^mersenne1[n])-1)%n)+1,a=a+1));return(a) Code:
(20:38)>a=0;for(n=1,100,if(2^valuation((((2^prime(n))-1)%n)+1,2)==(((2^prime(n))-1)%n)+1,a=a+1));return(a) %107 = 50 (20:39)>a=0;for(n=1,1000,if(2^valuation((((2^prime(n))-1)%n)+1,2)==(((2^prime(n))-1)%n)+1,a=a+1));return(a) %108 = 256 (20:39)>a=0;for(n=1,10000,if(2^valuation((((2^prime(n))-1)%n)+1,2)==(((2^prime(n))-1)%n)+1,a=a+1));return(a) %109 = 971 |
|
|
|
|
|
|
#2176 |
|
Aug 2006
3·1,993 Posts |
Incidentally, since you're working with Mersenne primes and exponents a lot, here's an idea for a script for your file:
Code:
MeVec=[2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433, 1257787, 1398269, 2976221, 3021377, 6972593, 13466917];
Me(n)={
if(n<=#MeVec,
MeVec[n]
,
error("not known")
)
};
addhelp(Me, "Me(n): Returns the n-th Mersenne prime exponent, Sloane's A000043.");
M(n,modulus=0)={
if(n>#MeVec, error("not known"));
if(modulus,
lift(Mod(2,modulus)^MeVec[n]-1)
,
1<<MeVec[n]-1
)
};
addhelp(M, "M(n, {modulus}): Returns the n-th Mersenne prime, Sloane's A000668. If modulus is given, instead return the n-th Mersenne number mod the modulus.");
This should not only save you keystrokes but time on longer calculations since the modular calculations are efficient compared to creating a large number and dividing it. |
|
|
|
|
|
#2177 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
Last fiddled with by science_man_88 on 2011-02-11 at 19:32 |
|
|
|
|
|
|
#2178 |
|
Aug 2006
3×1,993 Posts |
Can you prove that it behaves the way you expect mod 7? Mod 3? Mod 4?
|
|
|
|
![]() |
| 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 |