// A magic number is a number that repeated the sum of its digits
// #till we get a single digit is equal to 1
// 1729 = 1 + 7 + 2 + 9 = 19
// 19 = 1 + 9 = 10
// 10 = 1 + 0 = 1
using System;
class Program
{
static void Main() {
int num = 1729;
int digitCount = (int)Math.Log10(num) + 1;
int sumOfDigits = 0;
int temp = num;
while (digitCount > 1) {
sumOfDigits = 0;
while (temp > 0) {
sumOfDigits += temp % 10;
temp = temp / 10;
}
temp = sumOfDigits;
Console.WriteLine(sumOfDigits);
digitCount = (int)Math.Log10(sumOfDigits) + 1;
}
if (sumOfDigits == 1)
Console.Write("Magic number");
else
Console.Write("Not a magic number");
}
}
/*
run:
19
10
1
Magic number
*/