Skip to content

Instantly share code, notes, and snippets.

@kashwaa
Created March 7, 2014 11:39
Show Gist options
  • Save kashwaa/9410003 to your computer and use it in GitHub Desktop.
Save kashwaa/9410003 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace sqr
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
int res = 0;
int x = 10000000;
while (x!=0)
{
if (sqrchan89(x)) res++;
x--;
}
Console.WriteLine(res);
sw.Stop();
Console.WriteLine(sw.Elapsed);
Console.ReadLine();
}
public static int sqrSum(int number)
{
int res = 0;
while (number > 0)
{
int x = number % 10;
res += (int)Math.Pow(x,2);
number /= 10;
}
return res;
}
static bool sqrchan89(int number)
{
if (number == 89) return true;
else if (number == 1) return false;
else return sqrchan89(sqrSum(number));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment