Skip to content

Instantly share code, notes, and snippets.

@tomfuru
Created August 7, 2012 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfuru/3288237 to your computer and use it in GitHub Desktop.
Save tomfuru/3288237 to your computer and use it in GitHub Desktop.
dc20120807
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