看来解出了
开10000000/32大的数组来存商, 用int型的32位来存余数就能解了
开10000000/32大的数组来存商, 用int型的32位来存余数就能解了
#include<stdio.h> int main() { FILE *fp; char size[1000001]=""; int num,i,count=0; if((fp=fopen("F:\\aa.txt","r"))==NULL) { printf("open the file error!\n"); return 0; } for(i=0;i<1000000;i++) { if(feof(fp)) break; fscanf(fp,"%d",&num); if(size[num]==0) { size[num]='1'; count++; } } printf("count=%d\n",count); fclose(fp); return 0; }
//先在文件F:\\aa.txt中存放N个正整数M1,M2,....MN,(0< Mk <10000000),程序如下 #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { FILE *fp; char *size=(char *)malloc(10000000/8); memset(size,0,10000000/8); int num,i,count=0; if((fp=fopen("F:\\aa.txt","r"))==NULL) { printf("open the file error!\n"); return 0; } for(i=0;i<10000000;i++) { if(feof(fp)) break; fscanf(fp,"%d",&num); if((size[num/8]&(1<<num%8)) == 0) { size[num/8] |=(1<<num%8); count++; } } printf("count=%d\n",count); free(size); fclose(fp); return 0; }