time limit per test4 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.

He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:

Assume you’ve ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon’s vertex.

Your task is to calculate number of polygon’s sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon’s sides.

Input

There are only two numbers in the input: n and k (5 ≤ n ≤ 106, 2 ≤ k ≤ n - 2, gcd(n, k) = 1).

Output

You should print n values separated by spaces. The i-th value should represent number of polygon’s sections after drawing first i lines.

Examples

input

5 2

output

2 3 5 8 11

input

10 3

output

2 3 4 6 9 12 16 21 26 31

Note

The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.

For the first sample testcase, you should output “2 3 5 8 11”. Pictures below correspond to situations after drawing lines.



【题目链接】:http://codeforces.com/contest/755/problem/D

【题解】



两个点之间如果连一条线;

则如果这条线没有穿过其他线;

则平面+1

否则平面+=1+穿过的线条数;

假设当前是第now个点;

则看一下now+1..now+k-1这个范围内的点连的线的条数;即为这条线穿过的其他线的次数;

但是如果k>n/2了,那么可能连线的时候,now+1..now+k-1这些点有出边,但是不会和这条线相交.

比如

5 3



可以看到这里的第二条线.

虽然5 1 中1号点有出边,但是不会和新连的第二条线有交点;

这种情况下可以让n=n-k;

这时k< n/2

且答案是不会变的;

如上图可以把图左右倒过来.



LL以及上面这个是HACK点

写个线段树维护;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int MAXN = 1e6+100; int n,k;
LL sum[MAXN<<2]; LL query(int L,int R,int l,int r,int rt)
{
if (L>R)
return 0;
if (L <= l && r<=R)
return sum[rt];
int m = (l+r)>>1;
LL temp1=0,temp2=0;
if (L<=m)
temp1 = query(L,R,lson);
if (m < R)
temp2 = query(L,R,rson);
return temp1+temp2;
} void up_data(int pos,int l,int r,int rt)
{
if (l==r)
{
sum[rt]++;
return;
}
int m = (l+r)>>1;
if (pos<=m)
up_data(pos,lson);
else
up_data(pos,rson);
sum[rt] = sum[rt<<1]+sum[rt<<1|1];
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);rei(k);
k = min(k,n-k);
int now = 1;
LL ans = 1;
rep1(i,1,n)
{
int nex = now+k;
LL temp;
if (nex>n)
temp = query(now+1,n,1,n,1)+query(1,nex-n-1,1,n,1);
else
temp = query(now+1,nex-1,1,n,1);
ans += temp+1;
cout << ans;
if (i==n)
puts("");
else
putchar(' ');
up_data(now,1,n,1);
if (nex>n)
nex-=n;
up_data(nex,1,n,1);
now = nex;
}
return 0;
}

【codeforces 755D】PolandBall and Polygon的更多相关文章

  1. 【codeforces 755B】PolandBall and Game

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 【codeforces 755A】PolandBall and Hypothesis

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 755C】PolandBall and Forest

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 755F】PolandBall and Gifts

    [题目链接]:http://codeforces.com/contest/755/problem/F [题意] n个人; 计划是每个人都拿一个礼物来送给一个除了自己之外的人; 且如果一个人没有送出礼物 ...

  5. 【codeforces 755E】PolandBall and White-Red graph

    [题目链接]:http://codeforces.com/contest/755/problem/E [题意] 给你n个节点; 让你在这些点之间接若干条边;构成原图(要求n个节点都联通) 然后分别求出 ...

  6. Codeforces 755D:PolandBall and Polygon(思维+线段树)

    http://codeforces.com/problemset/problem/755/D 题意:给出一个n正多边形,还有k,一开始从1出发,向第 1 + k 个点连一条边,然后以此类推,直到走完 ...

  7. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  8. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  9. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

随机推荐

  1. 洛谷——P1316 丢瓶盖

    https://www.luogu.org/problem/show?pid=1316 题目描述 陶陶是个贪玩的孩子,他在地上丢了A个瓶盖,为了简化问题,我们可以当作这A个瓶盖丢在一条直线上,现在他想 ...

  2. Relaxation step(Dijkstra's 最短路径算法)

    翻译成中文就是"松弛",属于工程优化的范畴: Dijkstra 的单源最短路径算法,有一个重要的步奏,当访问到新的结点 u (加入到集合 S),然后遍历 u 的邻接顶点(Adj), ...

  3. Android网络框架OkHttp之get请求(源码初识)

    概括 OkHttp现在很火呀.于是上个星期就一直在学习OkHttp框架,虽然说起来已经有点晚上手了,貌似是2013年就推出了.但是现在它版本更加稳定了呀.这不,说着说着,OkHttp3.3版本在这几天 ...

  4. background-size在PC端和移动端使用媒体查询的不同

    1.PC端background-size:100%:是展现原图的大小. 2.使用媒体查询的移动端的background-size:100%:是根据内容的高度自动拉伸高度的.

  5. python一切皆对象的理解

    min_error=pls(x_train, x_test, y_train, y_test) #这里我之前写的是error,但是前面有一个定义的error函数.所以导致出现了警告. 可能是因为pyt ...

  6. kindle paperwhite 简单笔记按名称分类

    已更新python,见新博客  http://www.hrwhisper.me/archives/708 写作背景: 南京决赛比赛完那天晚上写的. 使用方法: 将My Clippings.txt 放在 ...

  7. mycat快速体验(转)

    横空出世的MyCat截至到2015年4月,保守估计已经有超过60个项目在使用,主要应用在电信领域.互联网项目,大部分是交易和管理系统,少量是信息系统.比较大的系统中,数据规模单表单月30亿.本人也初步 ...

  8. How to Rotate Tomcat catalina.out

    If catalina.out becomes 2GB in size, tomcat crashes and fails to start without any error message. To ...

  9. Fragment Summary 1/2

    转自:http://blog.csdn.net/lmj623565791/article/details/37970961 自从Fragment出现,曾经有段时间,感觉大家谈什么都能跟Fragment ...

  10. Loadrunner--常见问题及解决办法

    1.LR 脚本为空的解决方法: 1.去掉ie设置中的第三方支持取消掉 2.在系统属性-高级-性能-数据执行保护中,添加loadrunner安装目录中的vugen.exe文件 遇到flight界面为空的 ...