## CS13002 PDS Lab, Spring 2003, Section 1/AAssignment 2

1. [The year Y2K3]

Find the smallest positive integer t such that the decimal expansion of 2t starts with 2003, that is,

2t = 2003...,
that is, the four most significant decimal digits of 2t are 2003.

Note: For example 216 written in decimal is 65536. This expansion starts with 65, 655 etc. Your 2t should start with 2003 and may be followed by any number of other digits.

Hint: 2t satisfies the stated property if and only if
2003 * 10k <= 2t < 2004 * 10k
for some non-negative integer k. Now take logarithm to the base 10 and concentrate on the fractional parts.

2. [Primes in base seven]

Write functions to perform the following tasks:

• Check if a positive integer (provided as parameter) is prime.
• Check if a positive integer (provided as parameter) is composite.
• Return the sum S7(n) of the 7-ary digits of a positive integer n (supplied as parameter).

Use the above functions to find out the smallest positive integer i for which S7( pi ) is composite, where pi is the i-th prime. Also print the prime pi .

Note: 1 is neither prime nor composite. The sequence of primes is denoted by p1=2, p2=3, p3=5, p4=7, p5=11, ....

As an illustratuve example for this exercise consider the 31st prime p31 = 127 that expands in base 7 as
127 = 2 * 72 + 4 * 7 + 1,
i.e., the 7-ary expansion of 127 is 241 and therefore
S7(127)=2+4+1=7,
which is prime.

[Course home] [Home]