131k views
15 votes
Number Theory Problem: To transmit a positive integer less than 1000, the Networked Number Node offers two options.

Option 1. Pay $d to send each digit d. Therefore, 987 would cost $9 + $8 + $7 = $24 to transmit.
Option 2. Encode integer into binary (base 2) first, and then pay $d to send each digit d. Therefore, 987 becomes 1111011011 and would cost $1 + $1 + $1 + $1 + $0 + $1 + $1 + $0 + $1 + $1 = $8.
What is the largest integer less than 1000 that costs the same whether using Option 1 or Option 2?

User Coldstar
by
8.8k points

2 Answers

6 votes

Answer: 503

Explanation:

First, we need to find the largest possible value when sending a number with Option 2. If we had 10 1s the smallest binary number would be:

This is greater than 1000, so the greatest possible cost when sending with option 2 will be 9. We can look at the largest numbers less than 1000 which cost 9 with Option 1 and see if they cost 9 with option 2. The largest numbers are:

900, 810, 801, 720, 711, 702,...

The smallest possible number with 10 digits and cost 9 in Option 2 is: 10111111112 = 767

Below this, we would have:

which doesn't work. We can quickly check the numbers above and see that they cost less than 9 with method 2. So, we now need to consider numbers with cost of 8. The largest numbers with a cost of 8 in Option 1 are:

It is possible to check these in base 2 and see which is the first to cost 8 with Option 2, or we can go the other way and look at numbers with a cost of 8 in Option 2. Either way, we will find the largest possible integer with a cost of 8 is:

111110111₂ = 503

We must check and make sure that there are no numbers larger than 503 with an Option 2 cost lower than 8. The numbers with cost 7 in Option 1 with value greater than 503 are 700, 610, 601, and 520. We can check that all cost less than 7 in Option 2 and can be eliminated. The numbers with cost 6 in Option 1 with value greater than 503 are 600 and 510, neither of which have cost 6 in Option 2 and therefore do not work. Since a number with cost 5 or lower must be less than 500, the largest possible integer is 503

User Dharini S
by
8.5k points
9 votes

Answer:

In C, int requires 4 butes to sotre a integer number. that means it requires 4*8 = 32 bits. The maximum number can be stored using 32 bits is

The first digit is used for sign. decimal equivalent to this number can be computed as

=

=

That means int can store a up to 2147483646.

Testing with C code

#include<stdio.h>

int main()

{

int a = 2147483647; // a with max number

printf("%d\\",a);// printing max number

a = a+1;// adding one to the number

printf("%d\\",a);// printing the number after adding one

return 0;

}

THE OUTPUT

$ ./a.out

2147483647

-2147483648

Explanation:

PLEASE LIKE THIS OR LET IT BE HELPFUl

User Johnkreitlow
by
8.3k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories