Nyoj 46 least multiplication times

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.