Professional Documents
Culture Documents
Selected Exercises
Goal: Introduce fundamental number theory concepts:
• The division algorithm
• Congruences
• Rules of modular arithmetic
Exercise 10
Division Algorithm: Let a Z, d Z+. a d !q !r ( 0 r < d a = dq + r ).
What are the quotient & remainder when:
a) 44 is divided by 8? q: 5, r: 4.
b) 777 is divided by 21? q: 37, r: 0.
c) -123 is divided by 19? q: -7, r: 10. (not q = -6, r = -9)
d) -1 is divided by 23? q: -1, r: 22.
e) -2002 is divided by 87? q: -24, r: 86.
f) 0 is divided by 17? q: 0, r: 0.
g) 1,234,567 is divided by 1001? q: 1233, r: 334.
h) -100 is divided by 101? q: -1, r: 1.
Remember: remainders are always nonnegative.
( m | (a – b) )
Show:
if a ≡ b ( mod m ) and c ≡ d (mod m),
where a, b, c, d, m Z with m ≥ 2,
then a – c ≡ b – d ( mod m ).
Proof (Direct)
1. Assume ka Z, a = b + ka m ( Thm 4: a ≡ b (mod m) )
2. Assume kc Z, c = d + kc m ( Thm 4: c ≡ d (mod m) )
3. a – c = b – d + (ka – kc )m ( 1. – 2. )
4. a – c ≡ b – d ( mod m ) ( 3. & Thm 4 )
Copyright © Peter Cappello 4
Generating Pseudo-random
Numbers
• Generating pseudo-random numbers has important
applications.
• One application area is the Monte Carlo Method.
– Wikipedia
– MathWorld
• We glimpse 2 Monte Carlo Method applications crucial
to the survival of the human species.
– Approximate π
– Approximate winning probabilities in Texas Hold’em
1/2 ASQUARE = 1
1
ACIRCLE
---------- = π / 4
ASQUARE
( x, y )
If ( x2 + y2 ≤ 1/4 )
(0, 0 ) then (x, y) is “in” circle.
(- ½ , - ½ ) ½
Copyright © Peter Cappello 7
Use the Monte Carlo Method
Approximate π : via the Monte Carlo method:
double approximatePi( int n )
{
int inCircle = 0;
for ( int i = 0; i < n; i++ )
{
double x = rand( 0, 1 );
double y = rand( 0, 1 );
if ( isInCircle( x – 0.5, y – 0.5 ) )
inCircle++;
}
return ( 4.0 * inCircle ) / n; // value is a double
}
1. a modulus
2. a multiplier
3. an increment
4. a seed
5. the number ( n ) of pseudorandom numbers
14