How to check if a number is prime cyclops in C#

1 Answer

0 votes
// A number with an odd number of digits and zero in the center is Cyclops number

using System;

public class Program
{
	private static bool isCyclopsNumber(int n) {
		 if (n == 0) {
            return true;
        }
     
        int m = n % 10;
        int count = 0;
        while (m != 0) {
            count++;
            n /= 10;
            m = n % 10;
        }
     
        n /= 10;
        m = n % 10;
        while (m != 0) {
            count--;
            n /= 10;
            m = n % 10;
        }
     
        return n == 0 && count == 0;
	}
    private static bool isPrime(int n) {
		if (n < 2 || (n % 2 == 0 && n != 2)) {
			return false;
		}

		int count = (int)Math.Floor(Math.Sqrt(n)); 
		for (int i = 3; i <= count; i += 2) {
			if (n % i == 0) {
				return false;
			}
		}
		return true;
	}
	public static void Main(string[] args)
	{
		int n = 209;
        Console.WriteLine(isCyclopsNumber(n) && isPrime(n) ? "yes" : "no");
        
        n = 503;
        Console.WriteLine((isCyclopsNumber(n) && isPrime(n) ? "yes" : "no"));
	}
}






/*
run:
  
no
yes
  
*/

 



answered Mar 29, 2023 by avibootz
edited Apr 10, 2023 by avibootz

Related questions

1 answer 94 views
1 answer 124 views
1 answer 123 views
1 answer 98 views
1 answer 104 views
1 answer 95 views
1 answer 96 views
...