Created
August 7, 2012 18:45
-
-
Save tomfuru/3288237 to your computer and use it in GitHub Desktop.
dc20120807
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Application | |
{ | |
class MainClass | |
{ | |
/* | |
* 2^15 = 32768 であり、これの各数字の合計は 3 + 2 + 7 + 6 + 8 = 26 となる。 | |
* 同様にして、2^1000 の各数字の合計を求めよ。 | |
*/ | |
public static void Main(string[] args) | |
{ | |
List<int> vallist = new List<int>(); | |
vallist.Add(1); | |
for (int i = 1; i <= 1000; i++) { | |
for (int j = vallist.Count - 1; j >= 0; j--) { | |
int v = vallist[j]; | |
if (v >= 5) { | |
vallist[j] = (vallist[j] * 2) % 10; | |
if (j == vallist.Count - 1) { | |
vallist.Add(1); | |
} | |
else { | |
vallist[j + 1] += 1; | |
} | |
} | |
else { | |
vallist[j] *= 2; | |
} | |
} | |
} | |
Console.WriteLine(vallist.Aggregate((el, ac) => el + ac)); | |
} | |
} | |
} | |
// 1366 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment