1 #!/usr/local/src/cmd/calc/calc -q -s -f
3 * mersenne - print the value of a mersenne number
5 * Copyright (C) 1999-2007 Landon Curt Noll
7 * Calc is open software; you can redistribute it and/or modify it under
8 * the terms of the version 2.1 of the GNU Lesser General Public License
9 * as published by the Free Software Foundation.
11 * Calc is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 * Public License for more details.
16 * A copy of version 2.1 of the GNU Lesser General Public License is
17 * distributed with calc under the filename COPYING-LGPL. You should have
18 * received a copy with calc; if not, write to Free Software Foundation, Inc.
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * @(#) $Revision: 30.1 $
22 * @(#) $Id: mersenne.calc,v 30.1 2007/03/16 11:12:11 chongo Exp $
23 * @(#) $Source: /usr/local/src/bin/calc/cscript/RCS/mersenne.calc,v $
25 * Under source code control: 1999/11/30 00:09:01;
26 * File existed as early as: 1999
28 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
29 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
40 /* we include the name of this script in the error message */
41 fprintf(files(2), "usage: %s exp\n", config("program"));
42 abort "wrong number of args";
45 global n = eval(argv(1));
47 if (!isint(n) || n <= 0) {
48 quit "Argument to be a positive integer";
52 * print the decimal value of 2^n-1
54 print "2^": n : "-1 =", 2^n-1;