51nod 1419 最小公倍数挑战

来源:互联网 发布:原生js查看form 数据 编辑:程序博客网 时间:2024/05/22 13:47
1419 最小公倍数挑战
题目来源: CodeForces
基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题
收藏
关注

几天以前,我学习了最小公倍数。玩得挺久了,想换换口味。

我不想用太多的数字,我想从1n中选三个数字(可以相同)。使得他们的最小公倍数最大。


Input
单组测试数据。第一行有一个整数n (1≤n≤1,000,000)。
Output
输出一个整数表示选三个数字的最大的最小公倍数。
Input示例
97
Output示例
504210

提示:相邻两个数肯定不会有公约数

#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <string>#include <functional>#include <cmath>#include <set>#include <queue>#include <algorithm>#include <vector>#include <map>#include <stack>using namespace std;#define esp  1e-8const double PI = acos(-1.0);const double e = 2.718281828459;const int inf = 2147483647;const long long mod = 1000000007;//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cinint gcd(int a, int b){if (b == 0)return a;return gcd(b, a % b);}int main(){int n, i, j;while (~scanf("%d", &n)){long long ans = 0;for (i = n; i >= max(1, n - 1); --i){if (i & 1)ans = max(ans,  1LL * i * max(1, (i - 1)) * max(1, i - 2));else{int r1 = gcd(i, max(1, i - 2));int r2 = gcd(i, max(1, i - 3));ans = max(ans, max(1LL * i * max(1, (i - 1)) * max(1, i - 2) / r1, 1LL * i * max(1, (i - 1)) * max(1, i - 3) / r2));}}printf("%lld\n", ans);}}


0 0
原创粉丝点击