// 大家好——我现在正在测试第1000000000000000000000000000000000000个孪生素数,看看是多少哈哈
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef __int128 il;
int list[] = {2, 3, 5, 7, 19, 37, 53, 89, 113, 9973, 1000000007, 1000000009};
il ksc(il x, il y, il z)
{
il xx = 1;
il answer = xx * x * y % z;
return answer;
// if(y == 0) return 0;
// il w = ksc(x, y/ 2, z);
// w= (w + w) % z;
// if(y & 1)
// {
// w = (w + x) % z;
// }
// return w;
}
il ksm(il x, il y, il z)
{
if(y == 0) return 1;
il w = ksm(x, y /2 , z);
w= ksc(w, w, z);
if(y & 1)
{
w = ksc(w, x, z);
}
return w;
}
bool miller_rabin(il n,il a)
{
il d = n -1, r = 0;
while((d & 1) == 0)
{
d >>= 1;
r ++;
}
il x = ksm(a, d, n);
if(x== 1)
{
return true;
}
for(il i = 0; i <r ; i ++)
{
if(x == n - 1)
{
return true;
}
x =ksc(x, x, n);
}
return false;
}
bool isprime(il n )
{
if(n < 2) return false;
for(int a= 0;a< 12; a ++)
{
if(n == list[a])
{
return true;
}
if(n % list[a] == 0)
{
return false;
}
if(! miller_rabin(n, list[a]))
{
return false;
}
}
return true;
}
bool prime(il x)
{
return isprime(x);
}
bool ryan(__int128 x)
{
return prime(x) && prime(x + 2);
}
inline __int128 read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
inline void write(__int128 x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
int main()
{
__int128 x = read();
__int128 cnt = 0;
__int128 t;
for(__int128 i = 3; ; i ++)
{
if(ryan(i))
{
cnt ++;
t = i;
if(cnt == x)
{
write(t);
puts("");
write(t+2);
return 0;
}
}
}
return 0;
}
终极孪生素数
最新推荐文章于 2024-07-20 22:49:13 发布