RSS

Finding Fullness quotient of a number

Sat, Dec 12, 2009

Inverview Tips, Programming, Tutorials

Define the fullness quotient of an integer n> 0 to be the number of representations of n in bases 2 through 9 that have no zeroes after the most significant digit, For example, to see why the fullness quotient of 94 is 6 examine the following table which shows the representations of 94 in bases 2 through 9.

base: 2 representation of 94: 1011110(2 ^ 6 + 2 ^ 4 + 2 ^ 3 + 2 ^ 2 + 2 ^ 1 = 94)
base: 3 representation of 94: 10111(3 ^ 4 + 3 ^ 2 + 3 ^ 1 + 3 ^ 0 = 94) 
base: 4 representation of 94: 1132(4 ^ 3 + 4 ^ 2 + 3 * 4 ^ 1 + 2 * 4 ^ 0 = 94 )
base: 5 representation of 94: 334(3 * 5 ^ 2 + 3 * 5 ^ 1 + 4 * 4 ^ 0 = 94) 
base: 6 representation of 94: 234(2 * 6 ^ 2 + 3 * 6 ^ 1 + 4 * 6 ^ 0 = 94) 
base: 7 representation of 94: 163(1 * 7 ^ 2 + 6 * 7 ^ 1 + 3 * 7 ^ 0 = 94) 
base: 8 representation of 94: 136(1 * 8 ^ 2 + 3 * 8 ^ 1 + 6 * 8 ^ 0 = 94) 
base: 9 representation of 94: 114(1 * 9 ^ 2 + 1 * 9 ^ 1 + 4 * 9 ^ 0 = 94)

Notice that the representations of 94 in base 2 and 3 both have 0s after the most significant digit, but the representations in bases 4,5, 6, 7, 8, 9 do not. Since there are 6 such representations, the fullness quotient of 94 is 6

Write a method named fullnessQuotient that returns the fullness quotient of its argument. If the argument is less than 1 return -1. Its signature is
int fullnessQuotient (int n)
Hint: use modulo and integer arithmetic to convert n to its various representations

Example:

if n is: 1 return: 8, because: Because all of its representations do not have a 0 after the most significant digit: 2:1,3:1,4:1,5:1,6 : 1,7:1,8:1,9:1 
if n is: 9 return: 5, because: Because 5 of the representations (4, 5, 6, 7, 8) do not have a 0 after the most significant digit: 2:1001,3: 100,4:21,5:14,6:13,7:12,8:11,9:10 
if n is: 360 return: 0, because: All its representations have a 0 after the most significant digit: 2:101101000,3:111100,4:11220,5:2420,6:1400,7 : 1023,8:550,9:440 
if n is: -4 return: -1, because: The argument must be> 0
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Fullness Quotient: "+fullnessQuotient(9));
    }
 
    static int fullnessQuotient(int n)
             {
                     if (n <1)
                             return -1;
                     int count = 0;
 
                     for (int i = 2; i <10; i++)
                     {
                             if (isFullQuotient (n, i))
                                     count++;
                     }
 
                     return count;
             }
 
    private static bool isFullQuotient(int n, int b)
             {
                     int number = n;
                     do
                     {
                             if (number% b == 0)
                                     return false;
                     }while ((number /=b)!= 0);
                     return true;
             }
}

OUTPUT:

Fullness Quotient: 5
Sharing ~ Helping Other:
  • Print
  • email
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • BlinkList
  • DZone
  • Slashdot
  • YahooMyWeb
  • StumbleUpon
  • Live
  • IndianPad
  • DotNetKicks
  • Technorati

Related Posts:

,

This post was written by:

eXclusiveMinds - who has written 500 posts on eXclusiveMinds.


Contact the author

1 Comments For This Post

  1. Mukul Gupta Says:

    Here’s Solution in C:

    # include 
    # include 
    int fullnessQuotient (int n)
    {
    	 int count = 0;
    	 int temp;
    	 if (n <0) 
    	      return -1;
    	 for (int base = 2; base  0)
    			 {
    					 if (temp% base== 0)
    					 {
    					 count++; 
    					 break;
    					 }
    					 temp = temp / base;
    			 }
     
    	 {
    	 return 8-count;
    }
    int main ()
    {
    	 int num;
    	 printf( "Enter the number:");
    	 scanf( "% d", & num);
    	 printf( "the fullnessQuotient of% d is% d \ n", num, fullnessQuotient(num));
    	 getch();
    	 return 0;
    }

Leave a Reply

You must be logged in to post a comment.