Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <stdio.h>
- #include <string>
- #include <cmath>
- using namespace std;
- int check(int n)
- {
- int s=n;
- while (s%2==0)
- {
- s/=2;
- }
- if (s==1)
- return 1;
- else
- return 0;
- }
- void main(void)
- {
- int i=0,a[10]={0},n;
- while(1)
- {
- cin>>n;
- if (n==0)
- break;
- if (n==1)
- {
- a[i]=1;
- }
- else
- {
- if (check(n)==1)
- a[i]=(int)(log((double)n)/log(2.0));
- else
- a[i]=(int)(log((double)n)/log(2.0)+1);
- }
- i++;
- }
- for (int j=0;j<i;j++)
- printf("%d \n",a[j]);
- }
Add Comment
Please, Sign In to add comment