I want to find such prime numbers where the difference between the previous and the next is equal. Interestingly, this difference is always 6 or 12.
#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <fcntl.h> #define max 1000 int is_First(int value) { int i,sum; sum=0; for(i=1;i<value+1;i++) if(value%i==0) ++sum; if(sum==2) return 1; else return 0; } int prev_First(int value) { int i; i=value-1; for(;;) { if(is_First(i)) break; --i; } return i; } int next_First(int value) { int i; i=value+1; for(;;) { if(is_First(i)) break; ++i; } return i; } struct first_Point { int prev; int central; int next; int width1; int width2; }; int *tab_First; int main() { int i,j; tab_First=(int*)malloc(max+1); struct first_Point *f_Point; f_Point=malloc(max*sizeof(*f_Point)); if(tab_First==NULL) exit(1); if(f_Point==NULL) exit(1); i=0; j=3; do { if(is_First(j)) { tab_First[i]=j; f_Point[i].central=j; ++i; } ++j; }while(i<max); for(i=0;i<max;i++) { f_Point[i].prev=prev_First(f_Point[i].central); f_Point[i].next=next_First(f_Point[i].central); f_Point[i].width1=f_Point[i].central-f_Point[i].prev; f_Point[i].width2=f_Point[i].next-f_Point[i].central; } for(i=0;i<max;i++) { if(f_Point[i].width1==f_Point[i].width2) { printf("%d ---- %d ---- %d ---- %d ---- %d\n",f_Point[i].prev,f_Point[i].width1,f_Point[i].central, f_Point[i].width2,f_Point[i].next); } } free(f_Point); free(tab_First); getch(); return 0; }
Brak komentarzy:
Prześlij komentarz