Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
public static class IteratedDigitsSquaring
|
||||
{
|
||||
public static void Main() {
|
||||
Console.WriteLine(Count89s(1_000_000));
|
||||
Console.WriteLine(Count89s(100_000_000));
|
||||
}
|
||||
|
||||
public static int Count89s(int limit) {
|
||||
if (limit < 1) return 0;
|
||||
int[] end = new int[Math.Min(limit, 9 * 9 * 9 + 2)];
|
||||
int result = 0;
|
||||
|
||||
for (int i = 1; i < end.Length; i++) {
|
||||
for (end[i] = i; end[i] != 1 && end[i] != 89; end[i] = SquareDigitSum(end[i])) { }
|
||||
if (end[i] == 89) result++;
|
||||
}
|
||||
for (int i = end.Length; i < limit; i++) {
|
||||
if (end[SquareDigitSum(i)] == 89) result++;
|
||||
}
|
||||
return result;
|
||||
|
||||
int SquareDigitSum(int n) {
|
||||
int sum = 0;
|
||||
while (n > 0) {
|
||||
int digit = n % 10;
|
||||
sum += digit * digit;
|
||||
n /= 10;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
class Program {
|
||||
|
||||
const int MaxPow = 301;
|
||||
static int [] sq = {1, 4, 9, 16, 25, 36, 49, 64, 81};
|
||||
static BigInteger [] sums;
|
||||
|
||||
static bool is89(int x) {
|
||||
while (true) {
|
||||
int s = 0, t;
|
||||
do if ((t = (x % 10) - 1) >= 0) s += sq[t]; while ((x /= 10) > 0);
|
||||
if (s == 89) return true;
|
||||
if (s == 1) return false;
|
||||
x = s;
|
||||
}
|
||||
}
|
||||
|
||||
static BigInteger count89(int n) {
|
||||
BigInteger result = 0;
|
||||
for (int i = n * 81; i > 0; i--) {
|
||||
foreach (int s in sq) { if(s > i) break; sums[i] += sums[i - s]; }
|
||||
if (is89(i)) result += sums[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void Main(string[] args) {
|
||||
BigInteger [] t = new BigInteger[2] {1, 0}; sums = new BigInteger[MaxPow * 81]; Array.Copy(t, sums, t.Length);
|
||||
DateTime st = DateTime.Now;
|
||||
for (int n = 1; n < MaxPow; n++) {
|
||||
Console.Write("1->10^{0,-3}: {1}\n", n, count89(n));
|
||||
if ((DateTime.Now - st).TotalSeconds > 6) break;
|
||||
}
|
||||
Console.WriteLine("{0} seconds elapsed.", (DateTime.Now - st).TotalSeconds);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue