Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Created January 28, 2015 17:56
Show Gist options
  • Select an option

  • Save shohan4556/94a56f6e20b7445c1efe to your computer and use it in GitHub Desktop.

Select an option

Save shohan4556/94a56f6e20b7445c1efe to your computer and use it in GitHub Desktop.
Uva 10394 (Twin prime)
/// Author : Shohan
/// Uva 10394 (Twin prime)
#include<stdio.h>
#include<math.h>
#include<string.h>
#define N 20000000
char p[N];
unsigned long long int tp[N];
int main()
{
int i,j,root,t=1;
long long int n=0;
memset(p,1,sizeof p);
p[0]=p[1]=0;
root=sqrt(N);
for(i=2;i<=root;i++)
if(p[i]==1){
for(j=i+i;j<=N;j=j+i)
p[j]=0;
}
for(i=3;i<N;i++){
if(p[i]==1 && p[i+2]==1){
tp[t++]=i;
}
}
while(scanf("%lld",&n)==1){
printf("(%llu, %llu)\n",tp[n],tp[n]+2);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment