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,,,,,, because :: 2^6 + 2^4 + 2^3 + 2^2 + 2^1 = 94
base : 3 ,,, representation of 94 :10111 ,,,,,, because :: 3^4 + 3^2 + 3^1 + 3^0 = 94
base : 4 ,,, representation of 94 :1132 ,,,,,, because :: 4^3 + 4^2 + 3*4^1 + 2*4^0 = 94
base : 5 ,,, representation of 94 :334 ,,,,,, because :: 3*5^2 + 3*5^1 + 4*4^0 = 94
base : 6 ,,, representation of 94 :234 ,,,,,, because :: 2*6^2 + 3*6^1 + 4*6^0 = 94
base : 7 ,,, representation of 94 :163 ,,,,,, because :: 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 ,,,,,, because :: 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
Examples:
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
هذه احد اسئلة الماجستير لامتحانات القبول في احدى الجامعات الامريكية وبعد حل السؤال وبعثه قال لي انت مستواك بالبرمجة غير جيد وتحتاج إلى الكثير من الاجتهاد ولكن حسبي الله ونعم الوكيل فيهم
سوف اكتب لكم محاولتي في حل السؤال ولا اعلم هل هو صحيح ام اخاطئ فأرجوا من يقرأ هذا السؤال ان يقوم بشرحة وحله لكي اتأكد من الحل والفهم عندي ولكم جزيل الشكر والامتنان
المحاولة
int Convert(int base, int Input)
{
int Ret=0;
int factor = 10;
if(base < 2 || base > 10)
return 0;
Ret = Input % base;
while((Input /= base) > 0)
{
Ret = (Input % base) * factor + Ret;
factor *= 10;
}
return Ret;
}
int fullnessQuotient(int n)
{
int bRet=0;
for(int i= 2; i < 10; i++)
printf("Base %d => %d\n", i, Convert(i, n));
return bRet;
}
int main( )
{
int i;
i= fullnessQuotient (94);
return 0;
}
