Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int lg_floor(int x) {
- int c=-1;
- for(; x!=0; c++, x>>=1);
- return c;
- }
- int ops_for_number(int x) {
- return lg_floor(x&(-x));
- }
- int main(int argc, char *argv[]) {
- for(int n=128; n<256; n++) {
- double sum = 0;
- double result;
- for(int j=0; j<lg_floor(n); j++) {
- sum+=j*(1<<(lg_floor(n)-j-1));
- }
- for(int j=1<<lg_floor(n); j<=n; j++) {
- sum+=ops_for_number(j);
- }
- result = sum/n;
- printf("%f\n", result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement