POJ 3252 Round Numbers (Combinatorial mathematics)

Source: Internet
Author: User

Round Numbers
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 10223 Accepted: 3726

Description

The cows, as you know, has no fingers or thumbs and thus is unable to play Scissors, Paper, Stone ' (also known as ' Rock, Paper, Scissors ', ' Ro, Sham, Bo ', and a host of other names) in order to make arbitrary decisions such as who gets to be Milked first. They can ' t even flip a coin because it's so hard to toss using hooves.

They has thus resorted to "round number" matching. The first cow picks an integer less than and the billion. The second cow does the same. If The numbers is both "round numbers", the first cow wins,
Otherwise the second cow wins.

A positive integer n is said to being a "round number" if the binary representation of N has as many or mor E zeroes than it has ones. For example, the integer 9, when written in binary form, is 1001. 1001 has zeroes and ones; Thus, 9 is a round number. The integer is 11010 in binary; Since it has both zeroes and three ones, it is not a round number.

Obviously, it takes cows a while to convert numbers to binary, so the winner takes a and to determine. Bessie wants to cheat and thinks she can doing if she knows how many "round numbers" is in a given range.

Help she by writing a program that tells how many round numbers appear in the inclusive range given by the input (1≤ Start < Finish ≤2,000,000,000).

Input

Line 1:two space-separated integers, respectively Startand Finish.

Output

Line 1: A single integer So is the count of round numbers in the inclusive range Start.. Finish

Sample Input

2 12

Sample Output

6

Source



Test Instructions: Ask how many numbers are in the closed interval [n,m] round numbers, the so-called round numbers is to convert a decimal number in the closed interval to a number greater than or equal to 1 of the binary 0, then this number is round numbers



#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <        Stdlib.h>using namespace Std;int c[33][33] = {0};int bin[35];int n,m;void updata () {for (int i=0;i<=32;i++) {            for (int j=0;j<=i;j++) {if (j = = 0 | | i = = j) {C[i][j] = 1;            } else {c[i][j] = C[i-1][j-1] + c[i-1][j];    }}}}void Upbin (int x) {bin[0] = 0;        while (x) {bin[++bin[0]] = x%2;    x = X/2; } return;    int qurry (int x) {int sum = 0;    Upbin (x);        for (int i=1;i<bin[0]-1;i++) {for (int j=i/2+1;j<=i;j++) {sum + = c[i][j];    }} int zero = 0;  for (int i=bin[0]-1;i>=1;i--) {if (Bin[i]) {for (int j= (bin[0]+1)/2-(zero+1); j<=i-1;j++)            I can read this. {sum + = c[i-1][j];          }} else {  zero++; }} return sum;}    int main () {updata ();    scanf ("%d%d", &n,&m);    printf ("%d\n", Qurry (m+1)-qurry (n)); return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 3252 Round Numbers (Combinatorial mathematics)

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.