Minimum multiplication time limit: 1000 MS | memory limit: 65535 kb difficulty: 3
-
Description
-
A non-zero integer is given to you, asking you to calculate the N power of the number. The result of each multiplication can be used later to calculate the number of multiplication times. For example, 24:2*2 = 22 (first ride), 22*22 = 24 (second ride), so a total of 2;
-
Input
-
The first row of M indicates that there are m (1 <= m <= 100) groups of test data;
Each group of test data has an integer of N (0 <n <= 10000 );
-
Output
-
The number of times s required to output each group of test data;
-
Sample Input
-
3234
-
Sample output
-
122
-
-
#include<stdio.h>int main(){int m,n,a[16],i;for(i=0,m=1;i<=15;i++,m*=2)a[i]=m;scanf("%d",&m);while(m--){int sum;scanf("%d",&n);i=16;while(i--){if(n>=a[i]){n-=a[i];sum=i;break;}}while(n!=0){i=16;while(i--){if(n>=a[i]){n-=a[i];sum++;break;}}}printf("%d\n",sum);}}
-
Nyoj 46 least multiplication times