You are viewing a single comment's thread. Return to all comments →
C#
using System;
class Program { static int[] wut = new int[10000];
static void Shift(int[] arr, int arrsize) { for (int i = arrsize - 1; i >= 0; i--) { arr[i + 1] = arr[i]; } } static void Pre(int[] arr, int n) { arr[0] = 1; int arrsize = 1; int j = 0; while (n > 0) { for (int i = 0; i < arrsize; i++) { arr[i] = arr[i] * 2; if (i == 0) continue; else if (arr[i] >= 10) { arr[i - 1] += arr[i] / 10; arr[i] %= 10; } } while (arr[0] >= 10) { int temp = arr[0] / 10; arr[0] %= 10; Shift(arr, arrsize); arrsize++; arr[0] = temp; } int tong = 0; for (int i = 0; i < arrsize; i++) { tong += arr[i]; } wut[j] = tong; j++; n--; } } static void Main(string[] args) { int t; int[] arr = new int[3012]; Pre(arr, 10000); t = int.Parse(Console.ReadLine()); for (int a0 = 0; a0 < t; a0++) { int n; n = int.Parse(Console.ReadLine()); Console.WriteLine(wut[n - 1]); } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #16: Power digit sum
You are viewing a single comment's thread. Return to all comments →
C#
using System;
class Program { static int[] wut = new int[10000];
}