0%

Problem 315


Problem 315


Digital root clocks

Sam and Max are asked to transform two digital clocks into two “digital root” clocks.
A digital root clock is a digital clock that calculates digital roots step by step.

When a clock is fed a number, it will show it and then it will start the calculation, showing all the intermediate values until it gets to the result.
For example, if the clock is fed the number 137, it will show: “137“ → “11“ → “2“ and then it will go black, waiting for the next number.

Every digital number consists of some light segments: three horizontal (top, middle, bottom) and four vertical (top-left, top-right, bottom-left, bottom-right).
Number “1“ is made of vertical top-right and bottom-right, number “4“ is made by middle horizontal and vertical top-left, top-right and bottom-right. Number “8“ lights them all.

The clocks consume energy only when segments are turned on/off.
To turn on a “2“ will cost 5 transitions, while a “7“ will cost only 4 transitions.

Sam and Max built two different clocks.

Sam’s clock is fed e.g. number 137: the clock shows “137“, then the panel is turned off, then the next number (“11“) is turned on, then the panel is turned off again and finally the last number (“2“) is turned on and, after some time, off.
For the example, with number 137, Sam’s clock requires:

     
137 : (2 + 5 + 4) × 2 = 22 transitions (“137“ on/off).
11 : (2 + 2) × 2 = 8 transitions (“11“ on/off).
2 : (5) × 2 = 10 transitions (“2“ on/off).

For a grand total of 40 transitions.

Max’s clock works differently. Instead of turning off the whole panel, it is smart enough to turn off only those segments that won’t be needed for the next number.
For number 137, Max’s clock requires:

     
137 : 2 + 5 + 4 = 11 transitions (“137“ on)
7 transitions (to turn off the segments that are not needed for number “11“).
11 : 0 transitions (number “11“ is already turned on correctly)
3 transitions (to turn off the first “1“ and the bottom part of the second “1“;
the top part is common with number “2“).
2 : 4 transitions (to turn on the remaining segments in order to get a “2“)
5 transitions (to turn off number “2“).

For a grand total of 30 transitions.

Of course, Max’s clock consumes less power than Sam’s one.
The two clocks are fed all the prime numbers between A = 107 and B = 2×107.
Find the difference between the total number of transitions needed by Sam’s clock and that needed by Max’s one.


数根时钟

(左:萨姆的钟;右:马克斯的钟;下:在本题中钟面上的数字样式)

萨姆和马克斯被要求将两个数字时钟改装成两个“数根”时钟。
所谓数根时钟就是迭代计算数字根的数字时钟。

当时钟接收到一个数时,它会先显示这个数,然后开始计算,期间展示所有的中间值,直到它得到结果。
例如,如果时钟接收到的数是137,它会显示:”137“ → “11“ → “2“,然后它会黑屏,等待接收下一个数。

每个数字在钟面上用七段数码管显示:三根水平数码管(上、中、下)和四根竖直数码管(左上、右上、左下、右下)。
显示数字”1“需要点亮右上和右下的竖直数码管,显示数字”4“需要点亮中间的水平数码管和左上、右上、右下的竖直数码管,显示数字”8“则需要点亮所有的数码管。

只有在数码管打开或关闭时时钟才消耗能量。
因此,显示”2“需要5次转换,而”7“则只需要4次转换。

萨姆和马克斯制作了两个不同的时钟。

如果萨姆的时钟接收到一个数,比如说137:时钟先显示”137“,然后全部关掉,然后显示下一个数(“11“),再全部关掉,然后显示最后一个数(“2“),过一段时间后再全部关掉。
在这个例子中,接收到137后,萨姆的时钟需要消耗:

     
137 : (2 + 5 + 4) × 2 = 22次转换(显示和关闭”137“)。
11 : (2 + 2) × 2 = 8次转换(显示和关闭”11“)。
2 : (5) × 2 = 10次转换(显示和关闭”2“)。

总计需要40次转换。

马克斯的时钟运作的方式略有不同。它会很聪明地只关掉那些显示下一个数时不再用到的数码管,而不是全部关掉。
接收到137后,马克斯的时钟需要消耗:

     
137 : 2 + 5 + 4 = 11次转换(显示”137“ on)
7次转换(关闭显示”11“不需要的数码管)。
11 : 0次转换(”11“已经正确显示)
3次转换(关闭第一个”1“和第二个”1“的下半部分;
上半部分保留用于显示”2“)。
2 : 4次转换(显示”2“的剩余部分)
5次转换(关闭”2“)。

总计需要30次转换。

显然,马克斯的时钟比萨姆的时钟更节能。
这两个时钟随后依次接收到在A = 107和B = 2×107之间的所有质数。
求萨姆的时钟和马克斯的时钟所需要的转换次数的差。