
Exercises and problems in Informatics March 2002 
I. 19. Fermat's little theorem asserts that if p is a
prime and a is an integer not divisible by p, then
a^{p1}1 is divisible by p, that is
a^{p1}\(\displaystyle equiv\)1 (mod p).
For example, 2^{12}=4096 divided by 13 gives 1 as remainder.
However, the converse of Fermat's little theorem is false, that is
if a^{p1} is divisible by p, then
p is not necessarily a prime number. For example,
2^{340}\(\displaystyle equiv\)1 (mod 341), but 341=11^{.}31. Moreover, there
exist composite numbers p which satisfy Fermat's little theorem
for every number a<p, being relatively prime to
p. These p's are named  after their discoverer 
Carmichael numbers. The smallest such number is 561.
Write a program (I19.PAS,...) which reads two natural numbers
(1\(\displaystyle le\)NM100 000), then prints
all Carmichael numbers between N and M. (10
points)
I. 20. A sphere can be represented on the screen by
colouring the side being closer to us brighter than its farther
parts. Brightness is proportional to the cosine of the angle of
incidence of the light, and can be realized using pointcloud
representation: white points are placed on the black background very
densely at the brightest areas, and the dimmer a part is, the fewer
points it gets. Figure 1 shows the sphere illuminated by a
parallel beam of light emanating from our viewpoint. The beam on
Figure 2 has been rotated around the yaxis by
60 degrees relative to the axis of view.
Write a program (I20.PAS,...) which reads the angle between the beam
of light and the point of view, then displays the illuminated sphere
using pointcloud representation with a red circle placed on the
boundary. (10 points)
I. 21. Happy numbers are natural numbers with the
following property: summing the squares of their digits over and over
until the result becomes a onedigit number, we eventually reach the
number 1 itself. For example, 23 is a happy number, since
2^{2}+3^{2}=13, 1^{2}+3^{2}=10,
1^{2}+0^{2}=1. Some other happy numbers include, e.g.,
1 (because 1^{2}=1), 7 (because 7^{2}=4997130101), 10 (because
1^{2}+0^{2}=1), or 13 (because
1^{2}+3^{2}=10\(\displaystyle to\)1).
N  49 
Happy?  YES 
Total sum:  1 

Prepare a sheet (I21.XLS) which displays whether a given number
N is a happy number. The first 3 rows of your sheet should
look similar to the example given below. After the value of N
has been entered into cell B1, the result should appear in cells B2
and B3 upon simultaneously pressing the keys CTRL and M. (10
points)
Send your solutions to the following email address:
Deadline: 13 April 2002
