using System;
public class Test
{
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);
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJc3RhdGljIGJvb2wgSXNQcmltZShpbnQgbikKICAgICAgICB7CiAgICAgICAgICAgIGlmIChuIDw9IDMpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChuICUgMiA9PSAwIHx8IG4gJSAzID09IDApIAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7IAogICAgICAgICAgICB9CiAgICAgICAgICAgIGZvciAoaW50IGkgPSA1OyBpICogaSA8PSBuOyBpICs9IDYpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmIChuICUgaSA9PSAwIHx8IG4gJSAoaSArIDIpID09IDApIAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgICAgIH0gICAgICAgCiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHN0YXRpYyB2b2lkIFByaW50QWxsUVBvdzJwMVByaW1lTnVtYmVycyhpbnQgbikKICAgICAgICB7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAyOyBpPD1uOyBpKyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmIChJc1ByaW1lKGkpKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGlmIChNYXRoLlNxcnQoaS0xKSUxPT0wKSB7IENvbnNvbGUuV3JpdGVMaW5lKGkpOyB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIHN0YXRpYyB2b2lkIFByaW50QWxsRmlib25hY2NpUHJpbWVOdW1iZXJzKGludCBuKQogICAgICAgIHsKICAgICAgICAgICAgaW50IGkgPSAxOwogICAgICAgICAgICBpbnQgaV9wcnYgPSAxOwogICAgICAgICAgICBmb3IoaW50IGlfY3JudCA9IDI7aV9jcm50PD1uOyBpX2NybnQ9aV9wcnYraSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaSA9IGlfcHJ2OwogICAgICAgICAgICAgICAgaV9wcnYgPSBpX2NybnQ7CiAgICAgICAgICAgICAgICBpZiAoSXNQcmltZShpX2NybnQpKSB7IENvbnNvbGUuV3JpdGVMaW5lKGlfY3JudCk7IH0KICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgc3RhdGljIHZvaWQgTWFpbigpCiAgICAgICAgewogICAgICAgICAgICBDb25zb2xlLldyaXRlKCLQktCy0LXQtNGW0YLRjCDQutGA0LDQudC90Y4g0LzQtdC20YMg0LTQu9GPINC00ZbQsNC/0LDQt9C+0L3RgyBbMixuXToiKTsKICAgICAgICAgICAgaW50IG4gPSBpbnQuUGFyc2UoQ29uc29sZS5SZWFkTGluZSgpKTsKCiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCLQn9GA0L7RgdGC0ZYg0YfQuNGB0LvQsCDQstC40LPQu9GP0LTRgyBxXjIgKyAxOiIpOwogICAgICAgICAgICBQcmludEFsbFFQb3cycDFQcmltZU51bWJlcnMobik7CgogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgi0J/RgNC+0YHRgtGWINGH0LjRgdC70LAg0KTRltCx0L7QvdCw0YfRh9GWOiIpOwogICAgICAgICAgICBQcmludEFsbEZpYm9uYWNjaVByaW1lTnVtYmVycyhuKTsKICAgICAgICB9Cn0K