湘潭大学 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);
   }
}

posted on 2013-05-13 13:42  浪舟  阅读(328)  评论(0编辑  收藏  举报

导航