using System;
internal class Program
{
static bool IsPrime(int n)
{
if (n <= 3)
{
return true;
}
if (n % 2 == 0 || n % 3 == 0)
{
return false;
}
for (int i = 5; i * i <= n; i += 6)
{
if (n % i == 0 || n % (i + 2) == 0)
{
return false;
}
}
return true;
}
static void PrintAllQPow2p1PrimeNumbers(int n)
{
for (int i = 2; i<=n; i++)
{
if (IsPrime(i))
{
if (Math.Sqrt(i-1)%1==0) { Console.WriteLine(i); }
}
}
}
static void PrintAllFibonacciPrimeNumbers(int n)
{
int i = 1;
int i_prv = 1;
for(int i_crnt = 2;i_crnt<=n; i_crnt=i_prv+i)
{
i = i_prv;
i_prv = i_crnt;
if (IsPrime(i_crnt)) { Console.WriteLine(i_crnt); }
}
}
static void Main()
{
Console.Write("Введіть крайню межу для діапазону [2,n]:");
int n = int.Parse(Console.ReadLine());
Console.WriteLine("Прості числа вигляду q^2 + 1:");
PrintAllQPow2p1PrimeNumbers(n);
Console.WriteLine("Прості числа Фібоначчі:");
PrintAllFibonacciPrimeNumbers(n);
}
}
dXNpbmcgU3lzdGVtOwoKaW50ZXJuYWwgY2xhc3MgUHJvZ3JhbQp7CiAgICBzdGF0aWMgYm9vbCBJc1ByaW1lKGludCBuKQogICAgewogICAgICAgIGlmIChuIDw9IDMpCiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CiAgICAgICAgaWYgKG4gJSAyID09IDAgfHwgbiAlIDMgPT0gMCkgCiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gZmFsc2U7IAogICAgICAgIH0KICAgICAgICBmb3IgKGludCBpID0gNTsgaSAqIGkgPD0gbjsgaSArPSA2KQogICAgICAgIHsKICAgICAgICAgICAgaWYgKG4gJSBpID09IDAgfHwgbiAlIChpICsgMikgPT0gMCkgCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgfSAgICAgICAKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBzdGF0aWMgdm9pZCBQcmludEFsbFFQb3cycDFQcmltZU51bWJlcnMoaW50IG4pCiAgICB7CiAgICAgICAgZm9yIChpbnQgaSA9IDI7IGk8PW47IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIGlmIChJc1ByaW1lKGkpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZiAoTWF0aC5TcXJ0KGktMSklMT09MCkgeyBDb25zb2xlLldyaXRlTGluZShpKTsgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIHN0YXRpYyB2b2lkIFByaW50QWxsRmlib25hY2NpUHJpbWVOdW1iZXJzKGludCBuKQogICAgewogICAgICAgIGludCBpID0gMTsKICAgICAgICBpbnQgaV9wcnYgPSAxOwogICAgICAgIGZvcihpbnQgaV9jcm50ID0gMjtpX2NybnQ8PW47IGlfY3JudD1pX3ByditpKQogICAgICAgIHsKICAgICAgICAgICAgaSA9IGlfcHJ2OwogICAgICAgICAgICBpX3BydiA9IGlfY3JudDsKICAgICAgICAgICAgaWYgKElzUHJpbWUoaV9jcm50KSkgeyBDb25zb2xlLldyaXRlTGluZShpX2NybnQpOyB9CiAgICAgICAgfQogICAgfQoKICAgIHN0YXRpYyB2b2lkIE1haW4oKQogICAgewogICAgICAgIENvbnNvbGUuV3JpdGUoItCS0LLQtdC00ZbRgtGMINC60YDQsNC50L3RjiDQvNC10LbRgyDQtNC70Y8g0LTRltCw0L/QsNC30L7QvdGDIFsyLG5dOiIpOwogICAgICAgIGludCBuID0gaW50LlBhcnNlKENvbnNvbGUuUmVhZExpbmUoKSk7CgogICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCLQn9GA0L7RgdGC0ZYg0YfQuNGB0LvQsCDQstC40LPQu9GP0LTRgyBxXjIgKyAxOiIpOwogICAgICAgIFByaW50QWxsUVBvdzJwMVByaW1lTnVtYmVycyhuKTsKCiAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoItCf0YDQvtGB0YLRliDRh9C40YHQu9CwINCk0ZbQsdC+0L3QsNGH0YfRljoiKTsKICAgICAgICBQcmludEFsbEZpYm9uYWNjaVByaW1lTnVtYmVycyhuKTsKICAgIH0KfQ==