示例#1
0
int main(void)
{
	unsigned long l;

#ifdef LOADED
	unsigned long begin;

	/*
	 * round to the nearest multiple of 6
	 *
	 * note: the loaded test assumes we are starting above 3.
	 *
	 */

	begin = (LOWBALL < 6) ? 6 : LOWBALL - LOWBALL % 6;

	for(l=begin; l<=HIGHBALL; l+=6)
#else
	for(l=LOWBALL; l<=HIGHBALL; l+=1)
#endif
	{
#ifdef LOADED
		if(checkprime(l-1))
		{
			printf("\nBingo. %ld was prime.", l-1);
		}
		else
		{
			printf(".");
		}
		if(checkprime(l+1))
		{
			printf("\nBingo. %ld was prime.", l+1);
		}
		else
		{
			printf(".");
		}
#else
		if(checkprime(l))
		{
			printf("\nBingo. %ld was prime.", l);
		}
		else
		{
			printf(".");
		}
#endif
	}

	printf("\n");

	return 0;
}
int main(void)
{ if (checkprime(n))
    printf("Числото %u е просто. \n", n);
  else
    printf("Числото %u е съставно. \n", n);
  return 0;
}
示例#3
0
int main()
{
 int no=0,no_prime=0,val=0,pr=0,c=2;
unsigned long double mul_prime=1;
 printf("Enter No.Of Primes To Generate:");
 scanf("%d",&no);
printf("1.\t2\n");
printf("2.\t3\n");
 while(no_prime<(no-2))
{
 val++;
 pr=checkprime(val);
  if(pr==1)
  {
   no_prime++;
   c++;

   printf("%d.\t",c);
   printf("%d\n",val);
   mul_prime*=val;
  }
}
mul_prime*=6;
mul_prime++;
printf("\n\nThe Largest Prime Form Calculation=%f\n\n",mul_prime);


getch();
}
示例#4
0
int main(int argc, char **argv) {
    primelist *p=NULL, *q=NULL;
    long n, n_max, i, nd;
    n_max = atol(argv[1]); /* >=3 */
    head = calloc(1, sizeof(primelist));
    tail = head;
    tail->prime = 2;
    n = 2;
    while((n - 1) * (n - 1) < n_max) {
        n++;
        if (checkprime(n)) {
            q= calloc(1, sizeof(primelist));
            tail->next = q;
            tail = q;
            tail->prime = n;
        }
    }
    nd = (n_max - n + TMAX - 1) / (long) TMAX;
    for (i=0; i < TMAX; i++) {
        /* TMAX thread of checkprime loop */
        thd[i].n0 = n + 1; /* next unchecked */
        thd[i].n1 = n + nd;
        if (thd[i].n1 >= n_max) {
            thd[i].n1 = n_max;
        }
	n = thd[i].n1;
        if (pthread_create(&thd[i].th,
                NULL, 
                (void *) subthread, 
                (void *) &(thd[i]) ) ) {
            printf ("E: error creating thread at %li\n", i);
        }
    }
    for (i=0; i < TMAX; i++) {
        /* TMAX thread of checkprime loop */
        if (pthread_join(thd[i].th, (void *) NULL) ) {
            printf ("E: error joining thread at %li\n", i);
        }
        if (thd[i].head != NULL) { /* append if prime found */
            tail->next = thd[i].head;
            tail = thd[i].tail;
        }
    }

    p=head;
    while(p) {
        printf ("%ld\n", p->prime);
        p = p->next;
    }
    p=head;
    while(p) {
        q = p->next;
	    free(p);
	    p = q;
    }
    return EXIT_SUCCESS;
}
int main(){

    int t;
    scanf("%d",&t);
    while(t--){

         long long n;
         scanf("%lld",&n);
         if(checkprime(n,2)) printf("YES\n");
         else printf("NO\n");

    }
    return 0;

}
示例#6
0
文件: GreatyAdmis.c 项目: SJFOM/LCTHW
int main(int argc, char* argv[])
{ 
	int i;
	int b=1;
	k=725;
	p[1]=2;


	for(i=1; true ; i++)
	{
		
		if(checkprime(i)==1)
		{
			b++;
			p[b]=i;
			if(i>k)
			{  
				B=b;
				break;
			}
		}
	}
	
	a[1]=0; 
	for(i=2; i<=k; i++)
	{
		int j;
		for(j=a[i-1]+1; true; j++)
		{
			if(check(j, i)==1)
			{
				a[i]=j;
				//printf("%d", a[i]); 
				break;
			}
		}
		
	}
	
	
	int T=a[k]-a[1];
	printf("\n\nAdmissible tuple: %d, .., %d \n", a[1], a[k]);
	printf("\nWidth of our admissible tuple %d \n\n", T);

	return 0;	
}
示例#7
0
void subthread(thdata *thd) {
    long i;
    primelist *p=NULL, *q=NULL;
    thd->head = NULL;
    for (i = thd->n0; i <= thd->n1; i++) {
        if (checkprime(i)) {
            q = calloc(1, sizeof(primelist));
            q->prime = i;
            if (!thd->head) {
                thd->head = q;
                p = q;
            } else {
                p->next = q;
                p = q;
            }
            thd->tail = q;
        }
    }
}
示例#8
0
int getNextPrime (unsigned int n) 
{
    while ( !checkprime(++n) );
    return n; // all your primes are belong to us
}