hashtab * hash_new ( int size, hash_f hashfun, hash_cmp_f cmp) { hashtab *htab; int i; size = make_prime (size); htab = new hashtab[sizeof (*htab)]; if (htab == NULL) return NULL; htab->vec = (hashnode **)new hashnode[(size * sizeof (hashnode *))]; if (htab->vec == NULL) { delete (htab); return NULL; } htab->size = size; htab->cardinal = 0; htab->hashfun = hashfun; htab->cmp = cmp; for (i = 0; i < size; ++i) htab->vec[i] = NULL; return htab; }
/* {{{ apc_cache_create */ PHP_APCU_API apc_cache_t* apc_cache_create(apc_sma_t* sma, apc_serializer_t* serializer, zend_long size_hint, zend_long gc_ttl, zend_long ttl, zend_long smart, zend_bool defend) { apc_cache_t* cache; zend_long cache_size; zend_long nslots; /* calculate number of slots */ nslots = make_prime(size_hint > 0 ? size_hint : 2000); /* allocate pointer by normal means */ cache = (apc_cache_t*) apc_emalloc(sizeof(apc_cache_t)); /* calculate cache size for shm allocation */ cache_size = sizeof(apc_cache_header_t) + nslots*sizeof(apc_cache_slot_t*); /* allocate shm */ cache->shmaddr = sma->smalloc(cache_size); if(!cache->shmaddr) { apc_error("Unable to allocate shared memory for cache structures. (Perhaps your shared memory size isn't large enough?). "); return NULL; } /* zero shm */ memset(cache->shmaddr, 0, cache_size); /* set default header */ cache->header = (apc_cache_header_t*) cache->shmaddr; cache->header->nhits = 0; cache->header->nmisses = 0; cache->header->nentries = 0; cache->header->nexpunges = 0; cache->header->gc = NULL; cache->header->stime = time(NULL); cache->header->state |= APC_CACHE_ST_NONE; /* set cache options */ cache->slots = (apc_cache_slot_t**) (((char*) cache->shmaddr) + sizeof(apc_cache_header_t)); cache->sma = sma; cache->serializer = serializer; cache->nslots = nslots; cache->gc_ttl = gc_ttl; cache->ttl = ttl; cache->smart = smart; cache->defend = defend; /* header lock */ CREATE_LOCK(&cache->header->lock); /* zero slots */ memset(cache->slots, 0, sizeof(apc_cache_slot_t*)*nslots); return cache; } /* }}} */
int main(){ make_prime(); int n; while(scanf("%d",&n)==1){ if(n==0) break; int i; int temp; int count; for(i=count=0,temp=n;i<total&&prime[i]<=temp;i++) if(temp%prime[i]==0){ temp/=prime[i]; while(temp%prime[i]==0) temp/=prime[i]; count++;} if(temp!=1) count++; printf("%d : %d\n",n,count); } return 0; }
int main(){ make_prime(); char str[25]; while(gets(str)){ int i; int sum; bool found; for(sum=i=0;str[i]!='\0';i++) if(str[i]>='a'&&str[i]<='z') sum+=str[i]-'a'+1; else sum+=str[i]-'A'+27; for(i=0,found=false;i<total;i++) if(prime[i]==sum){ puts("It is a prime word."); found=true; break;} if(!found) puts("It is not a prime word."); } return 0; }
/* The main() is not required -- it's just a test driver */ int main(int argc, char *argv[]) { mp_int start; mp_err res; if(argc < 2) { fprintf(stderr, "Usage: %s <start-value>\n", argv[0]); return 1; } mp_init(&start); if(argv[1][0] == '0' && tolower(argv[1][1]) == 'x') { mp_read_radix(&start, argv[1] + 2, 16); } else { mp_read_radix(&start, argv[1], 10); } mp_abs(&start, &start); if((res = make_prime(&start, 5)) != MP_OKAY) { fprintf(stderr, "%s: error: %s\n", argv[0], mp_strerror(res)); mp_clear(&start); return 1; } else { char *buf = malloc(mp_radix_size(&start, 10)); mp_todecimal(&start, buf); printf("%s\n", buf); free(buf); mp_clear(&start); return 0; } } /* end main() */
int main(){ int n; make_prime(); while(scanf("%d",&n)==1){ if(n==0) break; int alive; int i,j,k,pre; int m[3502]; for(i=0;i<n;i++) m[i]=i+1; m[n-1]=0; alive=n; i=j=0; pre=n-1; while(alive>1){ for(k=1;k<prime[i];k++,pre=j,j=m[j]); // i 第i個被吃的人 m[pre]=m[j]; // j 目前數到的人 j=m[j]; // k 已經數了k個人 alive--,i++; } printf("%d\n",m[j]+1); } return 0; }