摘要: 输入:要生成的随机数的位数输出:随机数因为是32位系统,因此只能生成9位长度的10进制数。如果是10位的话可能会出现负数。溢出。#include<math.h>#include<time.h>#include<stdio.h>#include<stdlib.h>long MyRand(int n){ static int inited=0; long X,k=1; int i; if(!inited) { srand((unsigned)time(0)); inited=1; } if(n==1) return... 阅读全文
posted @ 2011-03-21 10:05 xwdreamer 阅读(2987) 评论(0) 推荐(0) 编辑
摘要: genPrime和genPrime2是筛法求素数的两种实现,其实是一个思路,表示方法不同而已。具体思路在注释中已经含有。#include<iostream> #include<math.h> #include<stdlib.h>using namespace std; const int MAXV = 100; //素数表范围 bool flag[MAXV+1]; //标志一个数是否为素数 int prime[MAXV+1]; //素数表,下标从0开始 int size=0; //素数个数 void genPrime(int max) { memset(fl 阅读全文
posted @ 2011-03-21 10:04 xwdreamer 阅读(5700) 评论(0) 推荐(3) 编辑