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))+1;
- }
- int main(int argc, char *argv[]) {
- for(int n=128; n<256; n++) {
- double sum = 0;
- double result;
- for(int j=1; j<=n; j++) {
- sum+=ops_for_number(j);
- }
- result = sum/n;
- printf("\n%f\n", result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement