原题链接:http://codeforces.com/contest/1040/problem/B
Shashlik Cooking
Long story short, shashlik is Miroslav’s favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over.
This time Miroslav laid out skewers parallel to each other, and enumerated them with consecutive integers from to in order from left to right. For better cooking, he puts them quite close to each other, so when he turns skewer number , it leads to turning closest skewers from each side of the skewer , that is, skewers number (if they exist).
For example, let and . When Miroslav turns skewer number , then skewers with numbers , and will come up turned over. If after that he turns skewer number , then skewers number , and will be turned over, while skewer number will be in the initial position (because it is turned again).
As we said before, the art of cooking requires perfect timing, so Miroslav wants to turn over all skewers with the minimal possible number of actions. For example, for the above example and , two turnings are sufficient: he can turn over skewers number and .
Help Miroslav turn over all skewers.
Input
The first line contains two integers and — the number of skewers and the number of skewers from each side that are turned in one step.
Output
The first line should contain integer — the minimum number of actions needed by Miroslav to turn over all skewers. After than print integers from to denoting the number of the skewer that is to be turned over at the corresponding step.
Examples
input
7 2
output
2
1 6
input
5 1
output
2
1 4
Note
In the first example the first operation turns over skewers and , the second operation turns over skewers and .
In the second example it is also correct to turn over skewers and , but turning skewers and , or and are incorrect solutions because the skewer is in the initial state after these operations.
题解
直接对 取模,如果余数大于 ,就可以直接在后面补一个;否则我们就把第一个也往前调一点。
代码
#include<bits/stdc++.h>
using namespace std;
const int M=1e3+5;
int n,k,st=1;
void in(){scanf("%d%d",&n,&k);}
void ac()
{
if(n%(2*k+1)>k)st=k+1,printf("%d\n",n/(2*k+1)+1);
else if(n%(2*k+1)==0)st=k+1,printf("%d\n",n/(2*k+1));
else printf("%d\n",n/(2*k+1)+1);
for(;st<=n;st+=2*k+1)printf("%d ",st);
}
int main(){in(),ac();}