首页 技术 正文
技术 2022年11月13日
0 收藏 782 点赞 4,145 浏览 975 个字

Number Transformation

我们能发现这个东西是以2 – k的lcm作为一个循环节, 然后bfs就好啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long longusing namespace std;const int N = 5e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-);LL a, b;
int k, lcm = ;
int dp[N];void getDp(int x) {
memset(dp, -, sizeof(dp));
dp[x] = ;
queue<int> que;
que.push(x);
while(!que.empty()) {
int u = que.front(); que.pop();
if(dp[u - ] == -) {
dp[u - ] = dp[u] + ;
que.push(u - );
}
for(int i = ; i <= k; i++) {
int v = u - (u % i);
if(~dp[v]) continue;
dp[v] = dp[u] + ;
que.push(v);
}
}
}int main() {
scanf("%lld%lld%d", &a, &b, &k);
swap(a, b);
for(int i = ; i <= k; i++)
lcm = lcm / __gcd(lcm, i) * i;
LL ans = ;
LL R = b - (b % lcm);
LL L = a + (lcm - a % lcm) % lcm;
if(L <= R) {
LL cnt = (R - L) / lcm;
getDp(lcm - );
ans = dp[] * cnt + cnt;
if(a % lcm) ans += dp[a % lcm] + ;
getDp(b % lcm);
ans += dp[];
} else {
getDp(b % lcm);
ans = dp[a % lcm];
}
printf("%lld\n", ans);
return ;
}/*
*/
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,090
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,567
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,415
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,187
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,824
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,907