Professional Documents
Culture Documents
}
}
long r_fact(int n)
{
if ((n==1) || (n==0)) return 1;
if (n < 0) {printf ("\nFor n < 0 n! is not defined!\n"); return 0;}
long t_fact(int n)
{
long factorials[17] = { 1,1,2,6,24,120,720,5040,40320,362880,3628800,
39916800,479001600,6227020800,87178291200,
1307674368000,20922789888000 };
return factorials[n];
}
(1)
n
n
Considering the main term is enough sometimes: n! 2n (2)
e
4! 24 (exact)
4! 24.00000347277858 (1) 1.447 105%
4! 23.50617513289329 (2) 2.101%
A monument to
Al-Khorezmi
in Tehran University
Elementary numerical analysis
Prime numbers search
Euclid: Let us assume that the number of primes is finite. Let us make a
product of all primes and then add a unit. The result cannot be divided by
any number of the finite set of primes, because the residual is a unit for all
these numbers. Hence, the result must be divided by a prime number which
is not included in the finite set. This is a contradiction.
$100,000
to the first individual or group who discovers a prime number with
at least 10,000,000 decimal digits (awarded Oct. 22, 2009)
$150,000
to the first individual or group who discovers a prime number with
at least 100,000,000 decimal digits
$250,000
to the first individual or group who discovers a prime number with
at least 1,000,000,000 decimal digits
http://w2.eff.org/awards/coop-prime-rules.php
Elementary numerical analysis
Prime numbers
How to find prime numbers?
Title: Bad method of searching prime numbers
Input data: Integer N
Required: Prime numbers between 2 and N
Start
CYCLE: i = 2, …, n
divisions = 0;
CYCLE: j = 1,…, i
IF i%j == 0,
THEN divisions ++;
END IF
IF divisions > 2
THEN break internal cycle;
END IF
END OF CYCLE
if divisions == 2
THEN print i // i is a prime number
END OF CYCLE
End
Elementary numerical analysis
Prime numbers
Sieve of Eratosphenes – a simple, ancient algorithm or finding all prime
numbers up to a specified integer number.
It works efficiently for the smaller primes (below 10 million).
None of his mathematical works survive, and the sieve was described and
attributed to Eratosthenes in the “Introduction to Arithmetic” by
Nicomachus (another one important ancient mathematician).
4. Find the first number remaining on the list greater than p (the next prime
and replace p with this number.
2
5. Repeat steps 3 and 4 until p is greater than n.
The first number in the list after 2 is 3; strike the multiples of 3 from the list:
2 3 5 7 11 13 17 19 23 25 29
The first number in the list after 3 is 5; strike the remaining multiples of 5:
2 3 5 7 11 13 17 19 23 29
The first number in the list after 5 is 7, but 7 squared is 49 which is greater than
30, so the process is finished.
See also: sieve of Sundaram, Sieve of Atkin, Euler’s sieve
Thank you!
There are 4 prime numbers between 1 and 9:
2, 3, 5, 7