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 q = 1; q*q+1<=n; q++)
{
if (IsPrime(q*q+1))
{
Console.WriteLine(q*q+1);
}
}
}
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);
}
}
dXNpbmcgU3lzdGVtOwppbnRlcm5hbCBjbGFzcyBQcm9ncmFtCnsKICAgIHN0YXRpYyBib29sIElzUHJpbWUoaW50IG4pCiAgICB7CiAgICAgICAgaWYgKG4gPD0gMykKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICBpZiAobiAlIDIgPT0gMCB8fCBuICUgMyA9PSAwKSAKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsgCiAgICAgICAgfQogICAgICAgIGZvciAoaW50IGkgPSA1OyBpICogaSA8PSBuOyBpICs9IDYpCiAgICAgICAgewogICAgICAgICAgICBpZiAobiAlIGkgPT0gMCB8fCBuICUgKGkgKyAyKSA9PSAwKSAKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICB9ICAgICAgIAogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIHN0YXRpYyB2b2lkIFByaW50QWxsUVBvdzJwMVByaW1lTnVtYmVycyhpbnQgbikKICAgIHsKICAgICAgICBmb3IgKGludCBxID0gMTsgcSpxKzE8PW47IHErKykKICAgICAgICB7CiAgICAgICAgICAgIGlmIChJc1ByaW1lKHEqcSsxKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUocSpxKzEpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIHN0YXRpYyB2b2lkIFByaW50QWxsRmlib25hY2NpUHJpbWVOdW1iZXJzKGludCBuKQogICAgewogICAgICAgIGludCBpID0gMTsKICAgICAgICBpbnQgaV9wcnYgPSAxOwogICAgICAgIGZvcihpbnQgaV9jcm50ID0gMjtpX2NybnQ8PW47IGlfY3JudD1pX3ByditpKQogICAgICAgIHsKICAgICAgICAgICAgaSA9IGlfcHJ2OwogICAgICAgICAgICBpX3BydiA9IGlfY3JudDsKICAgICAgICAgICAgaWYgKElzUHJpbWUoaV9jcm50KSkgeyBDb25zb2xlLldyaXRlTGluZShpX2NybnQpOyB9CiAgICAgICAgfQogICAgfQoKICAgIHN0YXRpYyB2b2lkIE1haW4oKQogICAgewogICAgICAgIENvbnNvbGUuV3JpdGUoItCS0LLQtdC00ZbRgtGMINC60YDQsNC50L3RjiDQvNC10LbRgyDQtNC70Y8g0LTRltCw0L/QsNC30L7QvdGDIFsyLG5dOiIpOwogICAgICAgIGludCBuID0gaW50LlBhcnNlKENvbnNvbGUuUmVhZExpbmUoKSk7CgogICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCLQn9GA0L7RgdGC0ZYg0YfQuNGB0LvQsCDQstC40LPQu9GP0LTRgyBxXjIgKyAxOiIpOwogICAgICAgIFByaW50QWxsUVBvdzJwMVByaW1lTnVtYmVycyhuKTsKCiAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoItCf0YDQvtGB0YLRliDRh9C40YHQu9CwINCk0ZbQsdC+0L3QsNGH0YfRljoiKTsKICAgICAgICBQcmludEFsbEZpYm9uYWNjaVByaW1lTnVtYmVycyhuKTsKICAgIH0KfQ==