Fairly straight forward this one…
________________
static void Main(string[] args)
{
int counter = 0;
for (long i = 2; i < 1000000; i++)
{
string s = i.ToString();
int l= s.ToString().Length;
int c = 0;
for (int x = 0; x <l; x++)
{
string sr = s.Substring(x, l - x) + s.Substring(0,x);
if (!isprime(Convert.ToInt32(sr)))
{
break;
}
else
{
c++;
}
}
if (c==l) {
counter++;}
}
Console.WriteLine(counter);
Console.ReadLine();
}
static bool isprime(int n)
{
if (n == 2 || n == 3 || n == 5) { return true; }
if (n%2==0) {return false;}
if (n%3 == 0) { return false;}
if (n%5 == 0) { return false;}
for (int t = 7; t < Math.Sqrt(n); t++)
{
if (n % t== 0)
{
return false;
}
}
return true;
}
No comments:
Post a Comment