315题：“更省电”的电子表

Sam的表显示的方式很直接：比如输入137，显示137，再关掉，一共需要(2 + 5 + 4) × 2 = 22次转换，137各个数字之和是11，显示11再关掉，(2 + 2) × 2 = 8次转换，最后的数字2，需要(5) × 2 = 10次转换。一共需要40次转换。

Max的表稍微智能一点：

```private static int[,] Overlap = new int[10, 10]
{
{ 6,2,4,4,3,4,5,4,6,5},
{ 2,2,1,2,2,1,1,2,2,2},
{ 4,1,5,4,2,3,4,2,5,4},
{ 4,2,4,5,3,4,4,3,5,5},
{ 3,2,2,3,4,3,3,3,4,4},
{ 4,1,3,4,3,5,5,3,5,5},
{ 5,1,4,4,3,5,6,3,6,5},
{ 4,2,2,3,3,3,3,4,4,4},
{ 6,2,5,5,4,5,6,4,7,6},
{ 5,2,4,5,4,5,5,4,6,6}
};```

```private static void Check()
{
var digital = new List<list>();
digital.Add(new List() { 1, 2, 3, 5, 6, 7 });
digital.Add(new List() { 3, 6 });
digital.Add(new List() { 1, 3, 4, 5, 7 });
digital.Add(new List() { 1, 3, 4, 6, 7 });
digital.Add(new List() { 2, 3, 4, 6 });
digital.Add(new List() { 1, 2, 4, 6, 7 });
digital.Add(new List() { 1, 2, 4, 5, 6, 7 });
digital.Add(new List() { 1, 2, 3, 6 });
digital.Add(new List() { 1, 2, 3, 4, 5, 6, 7 });
digital.Add(new List() { 1, 2, 3, 4, 6, 7 });
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
int overlap = digital[i].Intersect(digital[j]).Count();
if (overlap != Overlap[i, j])
{
Console.WriteLine(i + "t" + j + "t" + overlap);
}
}
}
}</list```

```private static int GetCount(int num1, int num2)
{
int count = 0;

while (num1 > 0 && num2 > 0)
{
count += Overlap[num1 % 10, num2 % 10];
num1 /= 10;
num2 /= 10;
}

return count;
}```

```private static int GetCount(int p)
{
int count = 0;
while (p >= 10)
{
int sum = p.ToString().Select(c => c-'0').Sum();
count += GetCount(p, sum);
p = sum;
}

return count * 2;
}```

```public static int GetAnswer()
{
Check();

int count = 0;
var primes = Utils.GenPrimes(20000000).Where(p => p > 10000000);

foreach (var p in primes)
{
count += GetCount((int)p);
}

return count;
}```

|