You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
728 B
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 50;
char str[N], tmp[N >> 4];
int main()
{
int T, n, L, R;
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &L, &R);
for (int i = L; i <= R; i++)
{
itoa(i, tmp, 2);
strcat(str, tmp);
}
int len = strlen(str);
int ans = 0;
for (int i = 0; i < len; i++)
{
if (memcmp(str + i, "010", 3) == 0) ans += 2;
if (memcmp(str + i, "101", 3) == 0) ans += 3;
}
printf("%d ", ans);
puts(str);
}
return 0;
}