cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A001220 Wieferich primes: primes p such that p^2 divides 2^(p-1) - 1.

This page as a plain text file.
%I A001220 #369 Jun 21 2025 11:49:27
%S A001220 1093,3511
%N A001220 Wieferich primes: primes p such that p^2 divides 2^(p-1) - 1.
%C A001220 Sequence is believed to be infinite.
%C A001220 Joseph Silverman showed that the abc-conjecture implies that there are infinitely many primes which are not in the sequence. - _Benoit Cloitre_, Jan 09 2003
%C A001220 Graves and Murty (2013) improved Silverman's result by showing that for any fixed k > 1, the abc-conjecture implies that there are infinitely many primes == 1 (mod k) which are not in the sequence. - _Jonathan Sondow_, Jan 21 2013
%C A001220 The squares of these numbers are Fermat pseudoprimes to base 2 (A001567) and Catalan pseudoprimes (A163209). - _T. D. Noe_, May 22 2003
%C A001220 Primes p that divide the numerator of the harmonic number H((p-1)/2); that is, p divides A001008((p-1)/2). - _T. D. Noe_, Mar 31 2004
%C A001220 In a 1977 paper, Wells Johnson, citing a suggestion from Lawrence Washington, pointed out the repetitions in the binary representations of the numbers which are one less than the two known Wieferich primes; i.e., 1092 = 10001000100 (base 2); 3510 = 110110110110 (base 2). It is perhaps worth remarking that 1092 = 444 (base 16) and 3510 = 6666 (base 8), so that these numbers are small multiples of repunits in the respective bases. Whether this is mathematically significant does not appear to be known. - _John Blythe Dobson_, Sep 29 2007
%C A001220 A002326((a(n)^2 - 1)/2) = A002326((a(n)-1)/2). - _Vladimir Shevelev_, Jul 09 2008, Aug 24 2008
%C A001220 It is believed that p^2 does not divide 3^(p-1) - 1 if p = a(n). This is true for n = 1 and 2. See A178815, A178844, A178900, and Ostafe-Shparlinski (2010) Section 1.1. - _Jonathan Sondow_, Jun 29 2010
%C A001220 These primes also divide the numerator of the harmonic number H(floor((p-1)/4)). - H. Eskandari (hamid.r.eskandari(AT)gmail.com), Sep 28 2010
%C A001220 1093 and 3511 are prime numbers p satisfying congruence 429327^(p-1) == 1 (mod p^2). Why? - _Arkadiusz Wesolowski_, Apr 07 2011. Such bases are listed in A247208. - _Max Alekseyev_, Nov 25 2014. See A269798 for all such bases, prime and composite, that are not powers of 2. - _Felix Fröhlich_, Apr 07 2018
%C A001220 A196202(A049084(a(1))) = A196202(A049084(a(2))) = 1. - _Reinhard Zumkeller_, Sep 29 2011
%C A001220 If q is prime and q^2 divides a prime-exponent Mersenne number, then q must be a Wieferich prime. Neither of the two known Wieferich primes divide Mersenne numbers. See Will Edgington's Mersenne page in the links below. - _Daran Gill_, Apr 04 2013
%C A001220 There are no other terms below 4.97*10^17 as established by PrimeGrid (see link below). - _Max Alekseyev_, Nov 20 2015. The search was done via PrimeGrid's PRPNet and the results were not double-checked. Because of the unreliability of the testing, the search was suspended in May 2017 (cf. Goetz, 2017). - _Felix Fröhlich_, Apr 01 2018. On Nov 28 2020, PrimeGrid has resumed the search (cf. Reggie, 2020). - _Felix Fröhlich_, Nov 29 2020. As of Dec 29 2022, PrimeGrid has completed the search to 2^64 (about 1.8 * 10^19) and has no plans to continue further. - _Charles R Greathouse IV_, Sep 24 2024
%C A001220 Are there other primes q >= p such that q^2 divides 2^(p-1)-1, where p is a prime? - _Thomas Ordowski_, Nov 22 2014. Any such q must be a Wieferich prime. - _Max Alekseyev_, Nov 25 2014
%C A001220 Primes p such that p^2 divides 2^r - 1 for some r, 0 < r < p. - _Thomas Ordowski_, Nov 28 2014, corrected by _Max Alekseyev_, Nov 28 2014
%C A001220 For some reason, both p=a(1) and p=a(2) also have more bases b with 1 < b < p that make b^(p-1) == 1 (mod p^2) than any smaller prime p; in other words, a(1) and a(2) belong to A248865. - _Jeppe Stig Nielsen_, Jul 28 2015
%C A001220 Let r_1, r_2, r_3, ..., r_i be the set of roots of the polynomial X^((p-1)/2) - (p-3)! * X^((p-3)/2) - (p-5)! * X^((p-5)/2) - ... - 1. Then p is a Wieferich prime iff p divides sum{k=1, p}(r_k^((p-1)/2)) (see Example 2 in Jakubec, 1994). - _Felix Fröhlich_, May 27 2016
%C A001220 Arthur Wieferich showed that if p is not a term of this sequence, then the First Case of Fermat's Last Theorem has no solution in x, y and z for prime exponent p (cf. Wieferich, 1909). - _Felix Fröhlich_, May 27 2016
%C A001220 Let U_n(P, Q) be a Lucas sequence of the first kind, let e be the Legendre symbol (D/p) and let p be a prime not dividing 2QD, where D = P^2 - 4*Q. Then a prime p such that U_(p-e) == 0 (mod p^2) is called a "Lucas-Wieferich prime associated to the pair (P, Q)". Wieferich primes are those Lucas-Wieferich primes that are associated to the pair (3, 2) (cf. McIntosh, Roettger, 2007, p. 2088). - _Felix Fröhlich_, May 27 2016
%C A001220 Any repeated prime factor of a term of A000215 is a term of this sequence. Thus, if there exist infinitely many Fermat numbers that are not squarefree, then this sequence is infinite, since no two Fermat numbers share a common factor. - _Felix Fröhlich_, May 27 2016
%C A001220 If the Diophantine equation p^x - 2^y = d has more than one solution in positive integers (x, y), with (p, d) not being one of the pairs (3, 1), (3, -5), (3, -13) or (5, -3), then p is a term of this sequence (cf. Scott, Styer, 2004, Corollary to Theorem 2). - _Felix Fröhlich_, Jun 18 2016
%C A001220 Odd primes p such that Chi_(D_0)(p) != 1 and Lambda_p(Q(sqrt(D_0))) != 1, where D_0 < 0 is the fundamental discriminant of the imaginary quadratic field Q(sqrt(1-p^2)) and Chi and Lambda are Iwasawa invariants (cf. Byeon, 2006, Proposition 1 (i)). - _Felix Fröhlich_, Jun 25 2016
%C A001220 If q is an odd prime, k, p are primes with p = 2*k+1, k == 3 (mod 4), p == -1 (mod q) and p =/= -1 (mod q^3) (Jakubec, 1998, Corollary 2 gives p == -5 (mod q) and p =/= -5 (mod q^3)) with the multiplicative order of q modulo k = (k-1)/2 and q dividing the class number of the real cyclotomic field Q(Zeta_p + (Zeta_p)^(-1)), then q is a term of this sequence (cf. Jakubec, 1995, Theorem 1). - _Felix Fröhlich_, Jun 25 2016
%C A001220 From _Felix Fröhlich_, Aug 06 2016: (Start)
%C A001220 Primes p such that p-1 is in A240719.
%C A001220 Prime terms of A077816 (cf. Agoh, Dilcher, Skula, 1997, Corollary 5.9).
%C A001220 p = prime(n) is in the sequence iff T(2, n) > 1, where T = A258045.
%C A001220 p = prime(n) is in the sequence iff an integer k exists such that T(n, k) = 2, where T = A258787. (End)
%C A001220 Conjecture: an integer n > 1 such that n^2 divides 2^(n-1)-1 must be a Wieferich prime. - _Thomas Ordowski_, Dec 21 2016
%C A001220 The above conjecture is equivalent to the statement that no "Wieferich pseudoprimes" (WPSPs) exist. While base-b WPSPs are known to exist for several bases b > 1 other than 2 (see for example A244752), no base-2 WPSPs are known. Since two necessary conditions for a composite to be a base-2 WPSP are that, both, it is a base-2 Fermat pseudoprime (A001567) and all its prime factors are Wieferich primes (cf. A270833), as shown in the comments in A240719, it seems that the first base-2 WPSP, if it exists, is probably very large. This appears to be supported by the guess that the properties of a composite to be a term of A001567 and of A270833 are "independent" of each other and by the observation that the scatterplot of A256517 seems to become "less dense" at the x-axis parallel line y = 2 for increasing n. It has been suggested in the literature that there could be asymptotically about log(log(x)) Wieferich primes below some number x, which is a function that grows to infinity, but does so very slowly. Considering the above constraints, the number of WPSPs may grow even more slowly, suggesting any such number, should it exist, probably lies far beyond any bound a brute-force search could reach in the forseeable future. Therefore I guess that the conjecture may be false, but a disproof or the discovery of a counterexample are probably extraordinarily difficult problems. - _Felix Fröhlich_, Jan 18 2019
%C A001220 Named after the German mathematician Arthur Josef Alwin Wieferich (1884-1954). a(1) = 1093 was found by Waldemar Meissner in 1913. a(2) = 3511 was found by N. G. W. H. Beeger in 1922. - _Amiram Eldar_, Jun 05 2021
%C A001220 From _Jianing Song_, Jun 21 2025: (Start)
%C A001220 The ring of integers of Q(2^(1/k)) is Z[2^(1/k)] if and only if k does not have a prime factor in this sequence (k is in A342390). See Theorem 5.3 of the paper of Keith Conrad. For example, we have:
%C A001220   (1 + 2^(364/1093) + 2^(2*364/1093) + ... + 2^(1092*364/1093))/1093 is an algebraic integer, but it is not in Z[2^(1/1093)];
%C A001220   (1 + 2^(1755/3511) + 2^(2*1755/3511) + ... + 2^(3510*1755/3511))/3511 is an algebraic integer, but it is not in Z[2^(1/3511)]. (End)
%D A001220 Richard Crandall and Carl Pomerance, Prime Numbers: A Computational Perspective, Springer, NY, 2001; see p. 28.
%D A001220 Richard K. Guy, Unsolved Problems in Number Theory, A3.
%D A001220 G. H. Hardy and E. M. Wright, An Introduction to the Theory of Numbers, 5th ed., Oxford Univ. Press, 1979, th. 91.
%D A001220 Yves Hellegouarch, "Invitation aux mathématiques de Fermat Wiles", Dunod, 2eme Edition, pp. 340-341.
%D A001220 Pace Nielsen, Wieferich primes, heuristics, computations, Abstracts Amer. Math. Soc., 33 (#1, 20912), #1077-11-48.
%D A001220 Paulo Ribenboim, The Book of Prime Number Records. Springer-Verlag, NY, 2nd ed., 1989, p. 263.
%D A001220 Paulo Ribenboim, The Little Book of Bigger Primes, Springer-Verlag NY 2004. See pp. 230-234.
%D A001220 David Wells, The Penguin Dictionary of Curious and Interesting Numbers, Penguin Books, NY, 1986, p. 163.
%H A001220 Takashi Agoh, Karl Dilcher and Ladislav Skula, <a href="http://dx.doi.org/10.1006/jnth.1997.2162">Fermat Quotients for Composite Moduli</a>, Journal of Number Theory 66(1), 1997, 29-50.
%H A001220 Joerg Arndt, <a href="http://www.jjj.de/fxt/#fxtbook">Matters Computational (The Fxtbook)</a>, p. 780.
%H A001220 Alex Samuel Bamunoba, <a href="http://dx.doi.org/10.1016/j.jnt.2016.09.036">A note on Carlitz Wieferich primes</a>, Journal of Number Theory, Vol. 174 (2017), pp. 343-357;
%H A001220 N. G. W. H. Beeger, <a href="https://archive.org/details/messengerofmathe5051cambuoft/page/148/mode/2up?view=theater">On a New Case of the Congruence 2^(p-1) == 1 (mod p^2)</a>, Messenger of Mathematics, Vol 51 (1922), pp. 149-150.
%H A001220 Dongho Byeon, <a href="https://citeseerx.ist.psu.edu/pdf/c2a375b9f8041c15c0de1833e6dcb48b2558c3af">Class numbers, Iwasawa invariants and modular forms</a>, Trends in Mathematics, Vol. 9, No. 1, (2006), pp. 25-29.
%H A001220 Chris K. Caldwell, The Prime Glossary, <a href="http://www.utm.edu/research/primes/glossary/WieferichPrime.html">Wieferich prime</a>.
%H A001220 Chris K. Caldwell, <a href="https://t5k.org/notes/proofs/SquareMerDiv.html">Prime-square Mersenne divisors are Wieferich</a>.
%H A001220 Denis Xavier Charles, <a href="http://www.cs.wisc.edu/~cdx/Criterion.pdf">On Wieferich Primes</a>.
%H A001220 Keith Conrad, <a href="https://kconrad.math.uconn.edu/blurbs/gradnumthy/integersradical.pdf">The ring of integers in a radical extension</a>.
%H A001220 Richard Crandall, Karl Dilcher and Carl Pomerance, <a href="https://doi.org/10.1090/S0025-5718-97-00791-6">A search for Wieferich and Wilson primes</a>, Mathematics of Computation, Vol. 66, No. 217 (1997), pp. 433-449; <a href="http://www.math.dartmouth.edu/~carlp/PDF/paper111.pdf">alternative link</a>.
%H A001220 Joe K. Crump, Joe's Number Theory Web, <a href="http://web.archive.org/web/20110728092734/http://www.immortaltheory.com/NumberTheory/Wieferich.htm">Weiferich Primes</a>. (sic)
%H A001220 John Blythe Dobson, <a href="https://johnblythedobson.org/mathematics/Wieferich_primes.html">A note on the two known Wieferich Primes</a>, 2007-2015.
%H A001220 John Blythe Dobson <a href="http://math.colgate.edu/~integers/s10/s10.Abstract.html">A Characterization of Wilson-Lerch Primes</a>, Integers, Vol. 16 (2016), A51.
%H A001220 John Blythe Dobson, <a href="https://arxiv.org/abs/2302.02027">On the special harmonic numbers H_floor(p/9) and H_floor(p/18) modulo p</a>, arXiv:2302.02027 [math.NT], 2023.
%H A001220 F. G. Dorais, <a href="http://www.math.cornell.edu/~dorais/index.php?page=software">WPSE - A Wieferich Prime Search Engine</a> (A program to search Wieferich primes written by F. G. Dorais.) - _Felix Fröhlich_, Jul 13 2014
%H A001220 François G. Dorais and Dominic W. Klyve, <a href="https://cs.uwaterloo.ca/journals/JIS/VOL14/Klyve/klyve3.html">A Wieferich Prime Search up to 6.7*10^15</a>, Journal of Integer Sequences, Vol. 14 (2011), Article 11.9.2.
%H A001220 Bruno Dular, <a href="https://arxiv.org/abs/1905.01765">Cycles of Sums of Integers</a>, arXiv:1905.01765 [math.NT], 2019.
%H A001220 Will Edgington, <a href="https://web.archive.org/web/20060630100606/http://www.garlic.com:80/~wedgingt/mersenne.html">Mersenne Page</a> [from Internet Archive Wayback Machine].
%H A001220 M. Goetz, <a href="http://www.primegrid.com/forum_thread.php?id=7436&amp;nowrap=true#107809">WSS and WFS are suspended</a>, PrimeGrid forum, Message 107809, May 11, 2017.
%H A001220 Andrew Granville and K. Soundararajan, <a href="http://dx.doi.org/10.1023/A:1009786614584">A binary additive problem of Erdős and the order of 2 mod p^2</a>, Raman. J., Vol. 2 (1998) pp. 283-298
%H A001220 Hester Graves and M. Ram Murty, <a href="http://www.mast.queensu.ca/~murty/Wieferich.pdf">The abc conjecture and non-Wieferich primes in arithmetic progressions</a>, Journal of Number Theory, Vol. 133 (2013), pp. 1809-1813.
%H A001220 René Gy, <a href="https://arxiv.org/abs/1902.05258">Extended Congruences for Harmonic Numbers</a>, arXiv:1902.05258 [math.NT], 2019.
%H A001220 Lorenz Halbeisen and Norbert Hungerbuehler, Number theoretic aspects of a combinatorial function, Notes on Number Theory and Discrete Mathematics 5 (1999) 138-150. (<a href="http://math.berkeley.edu/~halbeis/publications/psf/seq.ps">ps</a>, <a href="http://math.berkeley.edu/~halbeis/publications/pdf/seq.pdf">pdf</a>)
%H A001220 Stanislav Jakubec, <a href="http://matwbn.icm.edu.pl/ksiazki/aa/aa71/aa7114.pdf">Connection between the Wieferich congruence and divisibility of h+</a>, Acta Arithmetica, Vol. 71, No. 1 (1995), pp. 55-64.
%H A001220 Stanislav Jakubec, <a href="http://dx.doi.org/10.1090/S0025-5718-98-00916-8">On divisibility of the class number h+ of the real cyclotomic fields of prime degree l</a>, Mathematics of Computation, Vol. 67, No. 221 (1998), pp. 369-398.
%H A001220 Stanislav Jakubec, <a href="http://dx.doi.org/10.1006/jnth.1994.1050">The Congruence for Gauss Period</a>, Journal of Number Theory, Vol. 48, No. 1 (1994), pp. 36-45.
%H A001220 Wells Johnson, <a href="http://gdz.sub.uni-goettingen.de/dms/load/img/?PID=GDZPPN002193698">On the nonvanishing of Fermat quotients (mod p)</a>, Journal f. die reine und angewandte Mathematik, Vol. 292, (1977), pp. 196-200.
%H A001220 Jiří Klaška, <a href="https://cs.uwaterloo.ca/journals/JIS/VOL25/Klaska/klaska2.html">A Simple Proof of Skula's Theorem on Prime Power Divisors of Mersenne Numbers</a>, J. Int. Seq., Vol. 25 (2022), Article 22.4.3.
%H A001220 Jiří Klaška, <a href="https://cs.uwaterloo.ca/journals/JIS/VOL26/Klaska/klaska6.html">Jakóbczyk's Hypothesis on Mersenne Numbers and Generalizations of Skula's Theorem</a>, J. Int. Seq., Vol. 26 (2023), Article 23.3.8.
%H A001220 Joshua Knauer and Jörg Richstein, <a href="http://dx.doi.org/10.1090/S0025-5718-05-01723-0">The continuing search for Wieferich primes</a>, Math. Comp., Vol. 74, No. 251 (2005), pp. 1559-1563.
%H A001220 D. H. Lehmer, <a href="http://dx.doi.org/10.1090/S0025-5718-1981-0595064-5">On Fermat's quotient, base two</a>, Math. Comp., Vol. 36, No. 153 (1981), pp. 289-290.
%H A001220 Richard J. McIntosh and Eric L. Roettger, <a href="http://dx.doi.org/10.1090/S0025-5718-07-01955-2">A search for Fibonacci-Wieferich and Wolstenholme primes</a>, Math. Comp., Vol 76, No. 260 (2007), pp. 2087-2094.
%H A001220 C. McLeman, PlanetMath.org, <a href="http://planetmath.org/WieferichPrime">Wieferich prime</a>.
%H A001220 Waldemar Meissner, <a href="/A001917/a001917.pdf">Über die Teilbarkeit von 2^p-2 durch das Quadrat der Primzahl p = 1093</a>, Sitzungsberichte der Königlich Preussischen Akademie der Wissenschaften Berlin, Vol. 35 (1913), pp. 663-667. [Annotated scanned copy]
%H A001220 Sihem Mesnager and Jean-Pierre Flori, <a href="https://ia.cr/2012/033">A note on hyper-bent functions via Dillon-like exponents</a>, IACR, Report 2012/033, 2012.
%H A001220 Mishima Miwako and Koji Momihara, <a href="https://doi.org/10.1016/j.disc.2016.12.003">A new series of optimal tight conflict-avoiding codes of weight 3</a>, Discrete Mathematics, Vol. 340, No. 4 (2017), pp. 617-629. See page 618.
%H A001220 Alina Ostafe and Igor E. Shparlinski, <a href="http://arxiv.org/abs/1001.1504"> Pseudorandomness and Dynamics of Fermat Quotients</a>, arXiv:1001.1504 [math.NT], 2010.
%H A001220 Christian Perfect, <a href="http://aperiodical.com/2013/07/integer-sequence-reviews-on-numberphile-or-vice-versa/">Integer sequence reviews on Numberphile (or vice versa)</a>, 2013.
%H A001220 Reggie, <a href="http://www.primegrid.com/forum_thread.php?id=9436">Welcome to the Wieferich and Wall-Sun-Sun Prime Search</a>, PrimeGrid forum, 2020.
%H A001220 Reese Scott and Robert Styer, <a href="http://dx.doi.org/10.1016/j.jnt.2003.11.008">On p^x - q^y = c and related three term exponential Diophantine equations with prime bases</a>, Journal of Number Theory, Vol. 105, No. 2 (2004), pp. 212-234.
%H A001220 Vladimir Shevelev, <a href="http://arxiv.org/abs/0806.3412">Overpseudoprimes, Mersenne Numbers and Wieferich Primes</a>, arXiv:0806.3412 [math.NT], 2008.
%H A001220 Joseph Silverman, <a href="http://dx.doi.org/10.1016/0022-314X(88)90019-4">Wieferich's Criterion and the abc Conjecture</a>, J. Number Th. 30 (1988) 226-237.
%H A001220 Jonathan Sondow, <a href="http://arxiv.org/abs/1110.3113">Lerch quotients, Lerch primes, Fermat-Wilson quotients, and the Wieferich-non-Wilson primes 2, 3, 14771</a>, arXiv:1110.3113 [math.NT], 2012.
%H A001220 Jonathan Sondow, <a href="https://doi.org/10.1007/978-1-4939-1601-6_17">Lerch Quotients, Lerch Primes, Fermat-Wilson Quotients, and the Wieferich-non-Wilson Primes 2, 3, 14771</a>, Combinatorial and Additive Number Theory, CANT 2011 and 2012, Springer Proc. in Math. & Stat., Vol. 101 (2014), pp. 243-255.
%H A001220 Michel Waldschmidt, <a href="https://webusers.imj-prg.fr/~michel.waldschmidt/articles/pdf/abcLahoreProceedings.pdf">Lecture on the abc conjecture and some of its consequences</a>, Abdus Salam School of Mathematical Sciences (ASSMS), Lahore, 6th World Conference on 21st Century Mathematics 2013.
%H A001220 Michel Waldschmidt, <a href="http://www.math.jussieu.fr/~miw/articles/pdf/abcLahore2013VI.pdf">Lecture on the abc conjecture and some of its consequences</a>, Abdus Salam School of Mathematical Sciences (ASSMS), Lahore, 6th World Conference on 21st Century Mathematics 2013.
%H A001220 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/WieferichPrime.html">Wieferich Prime</a>.
%H A001220 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/abcConjecture.html">abc Conjecture</a>.
%H A001220 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/IntegerSequencePrimes.html">Integer Sequence Primes</a>.
%H A001220 A. Wieferich, <a href="http://resolver.sub.uni-goettingen.de/purl?GDZPPN002166968">Zum letzten Fermat'schen Theorem</a>, Journal für die reine und angewandte Mathematik, Vol. 136 (1909), pp. 293-302.
%H A001220 Wikipedia, <a href="http://en.wikipedia.org/wiki/Wieferich_prime">Wieferich prime</a>.
%H A001220 Paul Zimmermann, <a href="http://www.loria.fr/~zimmerma/records/primes.html">Records for Prime Numbers</a>.
%F A001220 (A178815(A000720(p))^(p-1) - 1) mod p^2 = A178900(n), where p = a(n). - _Jonathan Sondow_, Jun 29 2010
%F A001220 Odd primes p such that A002326((p^2-1)/2) = A002326((p-1)/2). See A182297. - _Thomas Ordowski_, Feb 04 2014
%p A001220 wieferich := proc (n) local nsq, remain, bin, char: if (not isprime(n)) then RETURN("not prime") fi: nsq := n^2: remain := 2: bin := convert(convert(n-1, binary),string): remain := (remain * 2) mod nsq: bin := substring(bin,2..length(bin)): while (length(bin) > 1) do: char := substring(bin,1..1): if char = "1" then remain := (remain * 2) mod nsq fi: remain := (remain^2) mod nsq: bin := substring(bin,2..length(bin)): od: if (bin = "1") then remain := (remain * 2) mod nsq fi: if remain = 1 then RETURN ("Wieferich prime") fi: RETURN ("non-Wieferich prime"): end: # Ulrich Schimke (ulrschimke(AT)aol.com), Nov 01 2001
%t A001220 Select[Prime[Range[50000]],Divisible[2^(#-1)-1,#^2]&]  (* _Harvey P. Dale_, Apr 23 2011 *)
%t A001220 Select[Prime[Range[50000]],PowerMod[2,#-1,#^2]==1&] (* _Harvey P. Dale_, May 25 2016 *)
%o A001220 (Haskell)
%o A001220 import Data.List (elemIndices)
%o A001220 a001220 n = a001220_list !! (n-1)
%o A001220 a001220_list = map (a000040 . (+ 1)) $ elemIndices 1 a196202_list
%o A001220 -- _Reinhard Zumkeller_, Sep 29 2011
%o A001220 (PARI)
%o A001220 N=10^4; default(primelimit,N);
%o A001220 forprime(n=2,N,if(Mod(2,n^2)^(n-1)==1,print1(n,", ")));
%o A001220 \\ _Joerg Arndt_, May 01 2013
%o A001220 (Python)
%o A001220 from sympy import prime
%o A001220 from gmpy2 import powmod
%o A001220 A001220_list = [p for p in (prime(n) for n in range(1,10**7)) if powmod(2,p-1,p*p) == 1]
%o A001220 # _Chai Wah Wu_, Dec 03 2014
%o A001220 (GAP) Filtered([1..50000],p->IsPrime(p) and (2^(p-1)-1) mod p^2 =0); # _Muniru A Asiru_, Apr 03 2018
%o A001220 (Magma) [p : p in PrimesUpTo(310000) | IsZero((2^(p-1) - 1) mod (p^2))]; // _Vincenzo Librandi_, Jan 19 2019
%Y A001220 Cf. similar primes related to the first case of Fermat's last theorem: A007540, A088164.
%Y A001220 Sequences "primes p such that p^2 divides X^(p-1)-1": A014127 (X=3), A123692 (X=5), A212583 (X=6), A123693 (X=7), A045616 (X=10), A111027 (X=12), A128667 (X=13), A234810 (X=14), A242741 (X=15), A128668 (X=17), A244260 (X=18), A090968 (X=19), A242982 (X=20), A298951 (X=22), A128669 (X=23), A306255 (X=26), A306256 (X=30).
%Y A001220 Cf. A001567, A002323, A077816, A001008, A039951, A049094, A126196, A126197, A178815, A178844, A178871, A178900, A246503, A247208, A269798.
%K A001220 nonn,hard,bref,nice,more
%O A001220 1,1
%A A001220 _N. J. A. Sloane_