CS13002 Programming and Data Structures | Section: 4/D, Spring 2005 |
Assignment 2
Write a program to determine the two positive integers with properties described below:
Part I
Find the smallest positive integer n with the following property. Let n = akak-1...a1a0 be the decimal expansion of n with ak > 0. Look at the integer nr = a0akak-1...a2a1 (the cyclic right shift of n). The desired property of n is that nr must be a proper integral multiple of n. Also report the multiplier nr/n.
Part II
Find the smallest positive integer n with the following property. Let n = akak-1...a1a0 be the decimal expansion of n with ak > 0. Look at the integer nl = ak-1ak-2...a1a0ak (the cyclic left shift of n). The desired property of n is that nl must be a proper integral multiple of n. Also report the multiplier nl/n.
Note: Write a single program. Use integer arithmetic only. Since integers cannot be arbitrarily large in C, report "failure" if your program fails to locate the desired value(s) of n after checking all n <= 109. There is no need to use arrays for solving this assignment. However, there is no penalty if you use them.
b is called a proper multiple of a, if b = ka for some integer k > 1.