int rand0_3() { return rand0_1()+rand0_1(); } int rand9() { int n=0; do{ n=(rand()7-1)*7+rand()7; }while(n>45) return n%9+1; }
int res = 0, bits = ceil(log(n)/log(2.0)); for(int i = 0; i < bits; i++){ if(rand01() == 1) res |= (1 << i); } if(res < n) return res;
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题