You are on page 1of 1

5.3.

NUMBER THEORY 
c Steven & Felix, NUS

// in int main()
sieve(100); // prepare list of primes [0 .. 100]
vi result = primeFactors(10000); // with that, we can factor up to 100^2 = 10000
vi::iterator last = unique(result.begin(), result.end()); // to remove duplicates
for (vi::iterator i = result.begin(); i != last; i++) // output: 2 and 5
printf("%d\n", *i);

In the worst case – when N is prime, this prime factoring algorithm with trial division requires
√ √ √ √
testing all smaller primes up to N, mathematically denoted as O(π( N )) = O( N /ln N ).
However, if given composite numbers, this algorithm is reasonably fast.

Programming Exercises about Prime Numbers problems:

1. UVa 294 - Divisors


2. UVa 406 - Prime Cuts
3. UVa 516 - Prime Land
4. UVa 524 - Prime Ring Problem (requires backtracking)
5. UVa 543 - Goldbach’s Conjecture
6. UVa 583 - Prime Factors
7. UVa 686 - Goldbach’s Conjecture (II)
8. UVa 897 - Annagramatic Primes
9. UVa 914 - Jumping Champion
10. UVa 993 - Product of digits
11. UVa 10006 - Carmichael Numbers
12. UVa 10042 - Smith numbers
13. UVa 10140 - Prime Distances
14. UVa 10200 - Prime Time
15. UVa 10235 - Simply Emirp (reverse prime)
16. UVa 10311 - Goldbach and Euler
17. UVa 10394 - Twin Primes (adjacent primes)
18. UVa 10533 - Digit Primes
19. UVa 10539 - Almost Prime Numbers
20. UVa 10637 - Coprimes
21. UVa 10650 - Determinate Prime (find 3 consecutive primes that are uni-distance)
22. UVa 10699 - Count the Factors
23. UVa 10738 - Riemann vs. Mertens
24. UVa 10789 - Prime Frequency
25. UVa 10852 - Less Prime
26. UVa 10924 - Prime Words
27. UVa 10948 - The Primary Problem
28. UVa 11287 - Pseudoprime Numbers
29. UVa 11408 - Count DePrimes
30. UVa 11466 - Largest Prime Divisor

97

You might also like