# Solution

100%:首先分析一下,我们知道在第i天1 * (m - i + 1)….k * (m - i + 1)会相连,于是总的边数就是$n/1+n/2+n/3...+n/n$$n / 1 + n / 2 + n / 3...+n / n$

# Code

#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 1e6 + 5;

struct ques
{
int x,y;
}a[N];

struct Edge
{
int to,val,next;
}edge[N << 1];

int n,m,q,x,y,tot;
int Rank[N],fa[N],st[N],depth[N];

int get(int x)
{
return fa[x] == x ? x : get(fa[x]);
}

{
edge[++tot].val = w;
if (Rank[x] > Rank[y])
{
fa[y] = x;
edge[tot].to = x;
edge[tot].next = st[y];
st[y] = tot;
}
else
{
fa[x] = y;
edge[tot].to = y;
edge[tot].next = st[x];
st[x] = tot;
if (Rank[x] == Rank[y]) Rank[x]++;
}
}

int query(int x,int y)
{
int depx = 0,depy = 0,ret = 0,jx = x,jy = y;
while (fa[jx] != jx) jx = fa[jx],depx++;
while (fa[jy] != jy) jy = fa[jy],depy++;
if (depx < depy) swap(depx,depy),swap(x,y);
while (depx > depy)
{
ret = max(edge[st[x]].val,ret);
x = fa[x];
depx--;
}
if (x == y) return ret;
while (x != y)
{
ret = max(ret,max(edge[st[x]].val,edge[st[y]].val));
x = fa[x],y = fa[y];
}
return ret;
}

int main()
{
freopen("pictionary.in","r",stdin);
freopen("pictionary.out","w",stdout);
scanf("%d%d%d",&n,&m,&q);
for (int i = 1 ; i <= n ; i++) fa[i] = i;
for (int i = 1 ; i <= m ; i++)
{
int t = m - i + 1;
for (int j = t + t ; j <= n ; j += t) link(get(t),get(j),i);
}
for (int i = 1 ; i <= q ; i++)
{
scanf("%d%d",&x,&y);
printf("%d\n",query(x,y));
}
fclose(stdin);
fclose(stdout);
return 0;
}