湘潭大学 ACM 1160 好题 快速模幂

http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1160

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;

int main( )
{
   int T,res; long long N;
   scanf("%d",&T);
   while( T-- )
   {
       scanf("%I64d",&N); res = 0;
       while( N )
       {
           if( N%2 )res++;
           if( N == 1 )break;
           res++;
           N/=2;
       }
       printf("%d\n",res);
   }
}
原文地址:https://www.cnblogs.com/wulangzhou/p/3075612.html