Saturday, September 22, 2018

Hexadecimal's Numbers

  • Problem Description

    "One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.
    But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.

    Input
    Input data contains the only number n (1<n<109).

    Output
    Output the only number answer to the problem.
    "
  • CODING ARENA
  • #include<stdio.h>
    int tot=0;

    void getNum(long long num,long long n)
    {
    if(num>n)
    return;
    tot++;
    num=num*10;
    getNum(num+1,n);
    getNum(num,n);
    }
    int main()
    {
        long long n;
        scanf("%lld",&n);
        getNum(1,n);
        printf("%d",tot);
        return 0;
    }
  • Test Case 1

    Input (stdin)
    10
    
    
    Expected Output
    2
  • Test Case 2

    Input (stdin)
    20
    
    
    Expected Output
    3

No comments:

Post a Comment