Skip to content

Instantly share code, notes, and snippets.

@shihongzhi
Created November 10, 2010 12:04
Show Gist options
  • Save shihongzhi/670763 to your computer and use it in GitHub Desktop.
Save shihongzhi/670763 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define BITNUMBER 32
#define N 10000000
#define random(x) rand()%x
int a[N/BITNUMBER+1];
void set(int i)
{
a[i/BITNUMBER]|=1<<(i%BITNUMBER);
}
void clean(int i)
{
a[i/BITNUMBER]&=~1<<(i%BITNUMBER);
}
int test(int i)
{
return (a[i/BITNUMBER]>>(i%BITNUMBER))&1;
}
int main()
{
int i,temp;
for(i=0;i<10000000;i++)
clean(i);
i=0;
while(i<1000000) //1000000个不重复的随机数
{
temp=random(10000000);
if(!test(temp)){
i++;
set(temp);
}
}
for(i=0;i<10000000;i++)
if(test(i))
printf("%d\n",i);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment