You are on page 1of 1

5.2.

AD HOC MATHEMATICS PROBLEMS 


c Steven & Felix, NUS

The appearance of mathematics problems in programming contests is not surprising since Computer
Science is deeply rooted in Mathematics. The term ‘computer’ itself comes from the word ‘compute’
as computer is built primarily to help human compute numbers.
We are aware that different countries have different emphasis in mathematics training in pre-
University education. Thus, for some newbie ICPC contestants, the term ‘Euler Phi’ is a familiar
term, but for others, the term does not ring any bell. Perhaps because he has not learnt it before, or
perhaps the term is different in his native language. In this chapter, we want to make a more level-
playing field for the readers by listing common mathematic terminologies, definitions, problems,
and algorithms that frequently appear in programming contests.

5.2 Ad Hoc Mathematics Problems


We start this chapter by mentioning Ad Hoc mathematics problems. They are basically contest
problems involving mathematics that requires no more than basic programming skills.

Programming Exercises related to Ad Hoc Mathematics:

1. UVa 344 - Roman Numerals (conversion from roman numerals to decimal and vice versa)
2. UVa 377 - Cowculations (base 4 operations)
3. UVa 10346 - Peter’s Smoke (simple math)
4. UVa 10940 - Throwing Cards Away II (find pattern using brute force, then use the pattern)
5. UVa 11130 - Billiard bounces (use billiard table reflection technique)
6. UVa 11231 - Black and White Painting (use the O(1) formula once you spot the pattern)
7. UVa 11313 - Gourmet Games (similar to UVa 10346)
8. UVa 11428 - Cubes (simple math with complete search)
9. UVa 11547 - Automatic Answer (one liner O(1) solution exists)
10. UVa 11723 - Numbering Road (simple math)
11. UVa 11805 - Bafana Bafana (very simple O(1) formula exists)

5.3 Number Theory


Mastering as many topics as possible in the field of number theory is important as some mathematics
problems becomes easy (or easier) if you know the theory behind the problems. Otherwise, either
a plain brute force attack leads to a TLE response or you simply cannot work with the given input
as it is too large without some pre-processing.

5.3.1 Prime Numbers


A natural number starting from 2: {2, 3, 4, . . .} is considered as a prime if it is only divisible by
1 or itself. The first (and the only even) prime is 2. The next prime numbers are: 3, 5, 7, 11, 13,
17, 19, 23, 29, . . . , and infinitely many more primes (proof in [20]). There are 25 primes in range
[0 . . . 100], 168 primes in [0 . . . 1000], 1000 primes in [0 . . . 7919], 1229 primes in [0 . . . 10000], etc...

94

You might also like