/* prnstewart.c Practical Number Search (Steward property) * * usage : * prnstewart MAXI > datafile * et si la dernière ligne de datafile est : rang nombre * on poursuit ainsi : * prnstewart rang nombre MAXI2 >> datafile * * compilation : * gcc -O2 -o prnstewart prnstewart.c; strip prnstewart * * prnstewart.c, Copyright (C) 2002 Jean-Paul Davalan. * * 29900 Concarneau (France) le : lun nov 25 00:00:09 CET 2002 * * $Modified: * * prnstewart is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * prnstewart is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with prnsteward; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * Jean-Paul Davalan */ #include #include #define MAXI 100000 /* retourne l'exposant, le nouveau n, la somme s=1+a+a^2+...+a^e */ inline int expos(int *n, int *s, int a) { int i; *s=1; for (i=0; *n % a == 0; i++) { *n = *n/a; *s = *s * a + 1; } return i; } /* pour n pair (supérieur à 1) */ inline int pntest(int n) { int k, x, s, somme, u; x = n; somme = 1; for(k=2; x >= k; k += (k==2)?1:2) { if((u=expos(&x, &s, k)) == 0) continue; if(k > somme+1) return 0; somme *= s; } return 1; } int main(int argc, char *argv[]) { int n, rang=1, mini=2, maxi= MAXI; if(argc <= 2) { printf("1 1\n"); if(argc==2) maxi=atoi(argv[1]); } else { rang = atoi(argv[1]); mini=atoi(argv[2])+1; if(mini%2 ==1) mini += 1; if(argc>3) maxi=atoi(argv[3]); } for(n=mini; n<= maxi; n+=2) { if(pntest(n)==1) { rang++; printf("%d %d\n",rang, n); } } return 0; }