[ACM]Q10235: Simply Emirp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace Q10235
{
class Program
{
static private BigInteger n; static private bool ntof;
static void Main(string[] args)
{
for (; ; )
{
labeln: Console.Write("n>>>");
ntof = BigInteger.TryParse(Console.ReadLine(), out n);
if (!ntof) goto labeln;
Console.WriteLine(isPrime(n) ? isPrime(reverse(n)) && reverse(n) != n ? n + " is emirp." : n + " is prime." : n + " is not prime.");
}
}
static public bool isPrime(BigInteger n)
{
int limit = (int)Math.Sqrt((double)n) + 1;
for (int i = 2; i <= limit; i++)
{
if (n % i == 0) return false;
}
return true;
}
static public BigInteger reverse(BigInteger n)
{
string str = "";
for (int i = 0; i < n.ToString().Length; i++)
{
str += n.ToString().Substring(n.ToString().Length - 1 - i, 1);
}
return BigInteger.Parse(str);
}
}
}