Created
January 28, 2015 17:56
-
-
Save shohan4556/94a56f6e20b7445c1efe to your computer and use it in GitHub Desktop.
Uva 10394 (Twin prime)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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