Submission details
Task:Lukuvälit
Sender:removed5096
Submission time:2019-10-12 13:29:08 +0300
Language:C++ (C++17)
Status:SKIPPED

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:76:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(a%powsOf10[i] != a)
       ~~~~~~~~~~~~~~^~~~
input/code.cpp:84:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (b % powsOf10[i] != b)
        ~~~~~~~~~~~~~~~~^~~~
input/code.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);;
  ~~~~~^~~~~~~~~~
input/code.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a);
   ~~~~~^~~~~~~~~~~~
input/code.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &b);
   ~~~~~^~~~~~~~~~~~

Code

#include<iostream>

unsigned long long powsOf10[19]
{
	1,
	10,
	100,
	1'000,
	10'000,
	100'000,
	1'000'000,
	10'000'000,
	100'000'000,
	1'000'000'000,
	10'000'000'000,
	100'000'000'000,
	1'000'000'000'000,
	10'000'000'000'000,
	100'000'000'000'000,
	1'000'000'000'000'000,
	10'000'000'000'000'000,
	100'000'000'000'000'000,
	1'000'000'000'000'000'000
};

unsigned long long ones[19]
{
	1,
	11,
	111,
	1'111,
	11'111,
	111'111,
	1'111'111,
	11'111'111,
	111'111'111,
	1'111'111'111,
	11'111'111'111,
	111'111'111'111,
	1'111'111'111'111,
	11'111'111'111'111,
	111'111'111'111'111,
	1'111'111'111'111'111,
	11'111'111'111'111'111,
	111'111'111'111'111'111,
	1'111'111'111'111'111'111
};

int main()
{
	int n;
	scanf("%d", &n);;

	long long a;
	long long b;
	long long temp;

	int toA = 0;
	int toB = 0;
	int between;

	int omA = 0;
	int omB = 0;

	bool aValid = false;

	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &a);
		scanf("%lld", &b);

		for (int i = 18; i >= 0; i--)
		{
			omA = i;

			if(a%powsOf10[i] != a)
				break;
		}

		for (int i = 18; i >= 0; i--)
		{
			omB = i;

			if (b % powsOf10[i] != b)
				break;
		}

		toA = 2 << omA;
		for (int i = 0; i < (1 << omA); i++)
		{
			temp = powsOf10[omA];
			for (int j = 0; j < omA; j++)
			{
				temp += powsOf10[j] * (i >> j & 1);
			}

			if (a < temp)
				toA--;
		}

		toB = 2 << omB;
		for (int i = 0; i < (1 << omB); i++)
		{
			temp = powsOf10[omB];
			for (int j = 0; j < omB; j++)
			{
				temp += powsOf10[j] * (i >> j & 1);
			}

			if (b < temp)
				toB--;
		}

		aValid = true;
		while (a > 0)
		{
			int remainder = a % 10;
			if (remainder > 1)
			{
				aValid = false;
				break;
			}
			a /= 10;
		}

		between = toB - toA + aValid;

		printf("%d\n", between);
	}

	return 0;
}