UV-575-Skew Binary (simple number theory !)

Source: Internet
Author: User
Tags cmath

UV-575-Skew Binary (simple number theory !)

 

Uvs-575 Skew Binary
Time Limit:3000 MS   Memory Limit:Unknown   64bit IO Format:% Lld & % llu

Submit Status

Description

 
Skew Binary

When a number is expressed in decimal,K-Th digit represents a multiple of 10K. (Digits are numbered from right to left, where the least significant digit is number 0.) For example,

 


 

When a number is expressed in binary,K-Th digit represents a multiple of 2K. For example,

 


 

InSkew binary,K-Th digit represents a multiple of 2K+ 1-1. The only possible digits are 0 and 1, cannot t that the least-significant nonzero digit can be a 2. For example,

 


 

The first 10 numbers in skew binary are 0, 1, 2, 10, 11, 12, 20,100,101, and 102. (Skew binary is useful in some applications because it is possible to add 1 with at most one carry. however, this has nothing to do with the current problem .)

 

InputThe input file contains one or more lines, each of which contains an integerN. IfN= 0 it signals the end of the input, and otherwiseNIs a nonnegative integer in skew binary.

 

OutputFor each number, output the decimal equivalent. The decimal valueNWill be at most 2 31-1 = 2147483647.

 

Sample Input
1012020000000000000000000000000000010100000000000000000000000000000011100111110000011100001011011020000

 

Sample Output
44214748364632147483647471041110737

 

 

Miguel A. Revilla
1998-03-10

Source


Root: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim): Mathematics: Ad Hoc Mathematics Problems: Base Number Variants
Root: aoapc I: Beginning Algorithm Contests (Rujia Liu): Volume 1. Elementary Problem Solving: Maths-Number Theory
Root: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim): Mathematics: Ad Hoc Mathematics Problems: Base Number Variants

 

 

 

AC code:

 

 

#include 
 
  #include 
  
   #include 
   
    #include #define LL long longusing namespace std;int main(){char a[40];while(scanf(%s, a)!=EOF){if(strlen(a)==1 && a[0] == '0')break;int len = strlen(a);LL bei=2, ans = 0;for(int i=len-1; i>=0; i--){ans += ( (bei-1) * (a[i]-'0') );bei*=2;}printf(%lld, ans);}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.