天天看点

codeforce 9C Hexadecimal's Numbers

Hexadecimal's Numbers

limit 1s,64M;

    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 ≤ 10^9).

Output

Output the only number—answer to the problem.

Example

Input

10

Output

2

题意

    计算所有小于n的01序列;

题解

    考虑n比较小,可以穷举

    用位运算枚举子集的方法枚举1到(1<<length)-1的所有数也就是长度等于n的所有01序列,逐位比较,可以得到答案。

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>

using namespace std;

char num[20];

bool check(int S,int n)
{
	for (int i=n-1;i>=0;--i)
	{
		int j=n-1-i;
		if (num[j]-'0'>(S>>i&1)) return true;
		if (num[j]-'0'<(S>>i&1)) return false;
	}
	return true;
}
int main(void)
{
	scanf("%s",num);
	int n=strlen(num); 
	
	int ans=0;
	for (int i=1;i<=(1<<n)-1;++i)
	{
		if (check(i,n)) ++ans;
	}
	
	printf("%d\n",ans);
}