Ultraviolet A 11645-Bits (number theory + counting problem)

Source: Internet
Author: User

Question link: 11645-Bits meaning: given a number n, the number of consecutive 11 in the binary format of 0-n is required. Idea: This is similar to the question of the remote control system. However, the biggest answer to this question is longlong, which requires high precision. Code:

# Include

 
  
# Include

  
   
Long n, a, B; const long DIG = 1e13; void add (long num) {B + = num; a + = B/DIG; B % = DIG;} int main () {int cas = 0; while (~ Scanf ("% lld", & n) & n> = 0) {a = B = 0; long tmp = n, d = 1; while (n> 1) {add (n> 2) * d); if (n & 3) = 3) add (tmp & (d-1) + 1 ); d <= 1; n >>= 1;} printf ("Case % d:", ++ cas); if (a) {printf ("% lld ", a); printf ("% 013lld \ n", B);} else printf ("% lld \ n", B);} return 0 ;}

  

 


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.