home > Project Euler >

ForNext

Shut the fuck up and write some code

Problem 16

累乗の各桁の和

であり, これの各桁の和は となる.

同様にして, の各桁の和を求めよ.

Power digit sum

and the sum of its digits is .

What is the sum of the digits of the number ?

VBScript

JScript

Perl

PHP

Python

Ruby

PowerShell

Scala

更新日 : 2013.01.31
scala> BigInt(2).pow(15)
res11: scala.math.BigInt = 32768

scala> BigInt(2).pow(100)
res12: scala.math.BigInt = 1267650600228229401496703205376
scala> BigInt(2).pow(100).toString.toCharArray
res14: Array[Char] = Array(1, 2, 6, 7, 6, 5, 0, 6, 0, 0, 2, 2, 8, 2, 2, 9, 4, 0, 1, 4, 9, 6, 7, 0, 3, 2, 0, 5, 3, 7, 6)
scala> BigInt(2).pow(100).toString.toCharArray.map(_.toInt)
res18: Array[Int] = Array(49, 50, 54, 55, 54, 53, 48, 54, 48, 48, 50, 50, 56, 50, 50, 57, 52, 48, 49, 52, 57, 54, 55, 48, 51, 50, 48, 53, 51, 55, 54)
scala> BigInt(2).pow(100).toString.toCharArray.map(_.toInt - 48)
res19: Array[Int] = Array(1, 2, 6, 7, 6, 5, 0, 6, 0, 0, 2, 2, 8, 2, 2, 9, 4, 0, 1, 4, 9, 6, 7, 0, 3, 2, 0, 5, 3, 7, 6)
scala> BigInt(2).pow(100).toString.toCharArray.map(_.toInt - 48).sum
res20: Int = 115
scala> BigInt(2).pow(1000).toString.toCharArray.map(_.toInt - 48).sum
res21: Int = 1366

F#

更新日 : 2013.01.30
> System.Numerics.BigInteger.Pow(2I,15);;
val it : System.Numerics.BigInteger = 32768I
> System.Numerics.BigInteger.Pow(2I,100);;
val it : System.Numerics.BigInteger = 1267650600228229401496703205376I
> System.Convert.ToString (System.Numerics.BigInteger.Pow(2I,100));;
val it : string = "1267650600228229401496703205376"
> (System.Convert.ToString (System.Numerics.BigInteger.Pow(2I,100))).ToCharArray();;
val it : char [] =
  [|'1'; '2'; '6'; '7'; '6'; '5'; '0'; '6'; '0'; '0'; '2'; '2'; '8'; '2'; '2';
    '9'; '4'; '0'; '1'; '4'; '9'; '6'; '7'; '0'; '3'; '2'; '0'; '5'; '3'; '7';
    '6'|]
> (System.Convert.ToString (System.Numerics.BigInteger.Pow(2I,100))).ToCharArray() |> Array.map(int);;
val it : int [] =
  [|49; 50; 54; 55; 54; 53; 48; 54; 48; 48; 50; 50; 56; 50; 50; 57; 52; 48; 49;
    52; 57; 54; 55; 48; 51; 50; 48; 53; 51; 55; 54|]
> (System.Convert.ToString (System.Numerics.BigInteger.Pow(2I,100))).ToCharArray() |> Array.map(int) |> Array.map(fun n -> n - 48);;
val it : int [] =
  [|1; 2; 6; 7; 6; 5; 0; 6; 0; 0; 2; 2; 8; 2; 2; 9; 4; 0; 1; 4; 9; 6; 7; 0; 3;
    2; 0; 5; 3; 7; 6|]
> (System.Convert.ToString (System.Numerics.BigInteger.Pow(2I,100))).ToCharArray() |> Array.map(int) |> Array.map(fun n -> n - 48) |> Array.sum;;
val it : int = 115
> (System.Convert.ToString (System.Numerics.BigInteger.Pow(2I,1000))).ToCharArray() |> Array.map(int) |> Array.map(fun n -> n - 48) |> Array.sum;;
val it : int = 1366

C

C++

C++Builder

VC++

C#

Java

Objective-C

D

VB

VB.NET

Delphi

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system