思路: 求lcm(1, 2, …, n, …, m) = lcm(n + 1, …, m)
根据算数基本定理
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
// #include <unistd.h>
#include <unordered_map>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define fi first
#define se second
#define mst(a, b) memset(a, b, sizeof a)
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
const int qq = 1e6 + 10;
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
LL gcd(LL a, LL b) {
return b == 0 ? a : gcd(b, a % b);
}
LL lcm(LL a, LL b) {
return a / gcd(a, b) * b;
}
int n;
int vis[qq];
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif
scanf("%d"

本文分享了腾讯笔试中的一道编程题,主要涉及求解最大公约数(LCM)和找寻循环节的问题。通过算数基本定理和深度优先搜索(DFS)策略进行解题,并利用抽屉原理和背包问题理论来解决循环节部分。
最低0.47元/天 解锁文章
9329

被折叠的 条评论
为什么被折叠?



