HDU 5272 Dylans loves numbers

Source: Internet
Author: User

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=5272

Dylans loves Numbersdescription

Who is Dylans? You can find its ID in Uoj and Codeforces.
His another ID is s1451900 in Bestcoder.

And now today ' s problems is all about him.

Dylans is given a number $N. $
He wants to the find out how many groups of "1" in its Binary representation.

If there is some "0" (at least one) that is between the "1",
Then we call these the "1" is not in a group,otherwise they is in a group.

Input

The first line there is a number $T. $

$T $ is the test number.

The next $T $ lines There is a number $N. $

$ \leq N \leq 10^{18},t \leq 1000$

Output

For each test case,output an answer.

Sampleinput

1

5

Sampleoutput

2

1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <map>8#include <Set>9 usingstd::cin;Ten usingstd::cout; One usingStd::endl; A usingStd::find; - usingStd::sort; - usingSTD::Set; the usingStd::map; - usingstd::p air; - usingstd::vector; - #defineSZ (c) (int) (c). Size () + #defineAll (c) (c). Begin (), (c). End () - #defineITER (c) __typeof ((c). Begin ()) + #defineCLS (arr,val) memset (arr,val,sizeof (arr)) A #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) at #defineRep (i, n) for (int i = 0; i < (int) (n); i++) - #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) - #definePB (E) push_back (e) - #defineMP (A, b) Make_pair (A, B) - Const intMax_n =100010; -typedef unsignedLong Longull; in intMain () { - #ifdef LOCAL toFreopen ("In.txt","R", stdin); +Freopen ("OUT.txt","w+", stdout); - #endif the     intT; * ull ret; $scanf"%d",&t);Panax Notoginseng      while(t--) { -         intf =1, ans =0;; thescanf"%lld",&ret); +          while(ret) { A             if(f) { the                 if(Ret &1) ans++, F =0; +}Else if(! (Ret &1)) F =1; -RET >>=1; $         } $printf"%d\n", ans); -     } -     return 0; the}
View Code

HDU 5272 Dylans loves numbers

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.