Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties:
- for all x
the following inequality holds l ≤ x ≤ r;
- 1 ≤ |S| ≤ k;
- lets denote the i-th element of the set S as si; value
must be as small as possible.
Help Victor find the described set.
The first line contains three space-separated integers l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)).
Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order.
If there are multiple optimal sets, you can print any of them.
8 15 3
1 2 10 11
8 30 7
0 5 14 9 28 11 16
1. k=1,则答案为l
k=3的情况讲得不是很清楚:我们要尽可能地凑出答案为0的情况。那么如下,当每一列的1成对存在时,答案就是0,。
1010100001
0010101001
1001001000
假设有这样三个数:
a:11xxxxxxx
b:10yyyyyyy
c:01zzzzzzz
它们必然满足a>b>c,为了使a和c尽量落在[l,r]之间,则c尽量地大,取011111111,a尽量地小,取110000000。所以只要110000000<r,答案就是0。
顺便说一句,c可以取[l,011111111]之间的任意数,因为我始终可以通过调整b的值(确切地讲就是c有0的地方b也是0,c有1的地方b也是1)来保障a取110000000。
注意:位运算的优先级比&& || < <= == > >=等低。
#include<cstdio>
using namespace std;
typedef long long LL;
LL l,r,k;
void work()
{
if(k>=4 && !(l&1)) {printf("0\n4\n%I64d %I64d %I64d %I64d",l,l+1,l+2,l+3);return;}
if(k>=4 && (l&1) && (l+4<=r)){printf("0\n4\n%I64d %I64d %I64d %I64d",l+1,l+2,l+3,l+4);return;}
if(k>=3)
{
LL i=1;
for(;i<=l;i=i<<1);
if(r>=i+(i>>1)) {printf("0\n3\n%I64d %I64d %I64d",l,l^(i+(i>>1)),i+(i>>1));return;}
}
if(k>=2)
{
if(l+1==r && (l&1))//odd+even
if((l^r)>=l) {printf("%I64d\n1\n%I64d",l,l); return;}//l
else {printf("%I64d\n2\n%I64d %I64d",l^r,l,r); return;}//l^r
printf("1\n2\n");
if(l&1)//l is odd
printf("%I64d %I64d",l+1,l+2);//1
else printf("%I64d %I64d",l,l+1);//1
return;
}
if(k>=1) {printf("%I64d\n1\n%I64d",l,l); return;}//l
}
int main()
{
while(scanf("%I64d%I64d%I64d",&l,&r,&k)==3)
{
work();
printf("\n");
}
return 0;
}