关键:求最小公倍数+堆优化dijkstra
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
typedef pair<int ,int>PII;
const int N=2050,M=N*N;
int n=2021;
struct E
{
int to,w,next;
}doge[M];
int head[N],cnt;
int dis[N];
bool vis[N];
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b)
{
return a/gcd(a,b)*b;
}
void add(int u,int v,int w)
{
doge[++cnt].to=v,doge[cnt].w=w,doge[cnt].next=head[u],head[u]=cnt;
}
void dijkstra()
{
memset(dis,0x3f,sizeof dis);
dis[1]=0;
priority_queue<PII,vector<PII>,greater<PII>>q;
q.push({0,1});
while(q.size())
{
int t=q.top().second;
q.pop();
if(vis[t])continue;
vis[t]=1;
for(int i=head[t];i!=0;i=doge[i].next)
{
int j=doge[i].to;
if(dis[j]>dis[t]+doge[i].w)
{
dis[j]=dis[t]+doge[i].w;
q.push({dis[j],j});
}
}
}
}
int main()
{
for(int i=1;i<=n;i++)
for(int j=i+1;j-i<=21;j++)
{
int k=lcm(i,j);
add(i,j,k),add(j,i,k);
}
dijkstra();
cout<<dis[n]<<endl;
return 0;
}