LCM Challenge

Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others)
Submit Status

Problem Description

Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.

But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?

Input

The first line contains an integer n (1 ≤ n ≤ 10^6) — the n mentioned in the statement.

Output

Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.

Sample Input

9

Sample Output

504

题意:给一个数n,要求找3个小于等于n的数,3个数的最小公倍数LCM(a1,a2,a3)最大。

分析:其实就是要找3个两两互质的数,但是只是如何找的问题。

  根据连续的两个奇数互质,连续的两个自然数互质。那么答案很明显了,3个最大的互质的数的最小公倍数肯定最大。

  如果n是奇数,那么答案是n*(n-1)*(n-2)。

  如果n是偶数就麻烦了点,要么是如果n和n-2互质,那么答案就是n*(n-1)*(n-2),因为他们是最大的3个互质的数。但是如果是n和n-2不互质,那么答案是(n-3)*(n-1)*(n-2),因为n-1之后肯定是奇数了,用奇数的方法。

 /*
* this code is made by xcw0754
* Problem: 1077
* Verdict: Accepted
* Submission Date: 2015-07-16 10:24:02
* Time: 0MS
* Memory: 1672KB
*/
#include <bits/stdc++.h>
#define LL long long
#define pii pair<int,int>
#define INF 0x7f7f7f7f
using namespace std;
const int N=+; LL cal(LL n) //偶数
{
LL ans=;
//n n-1 n-3
if(__gcd(n,n-)==) ans=max(ans, n*(n-)*(n-)); //n-1 n-2 n-3
ans=max(ans, (n-)*(n-)*(n-)); return ans;
} int main()
{
//freopen("input.txt", "r", stdin);
LL n;
scanf("%lld",&n);
if(n==) printf("1\n");
else if(n==) printf("2\n");
else if(n==) printf("6\n");
else if(n==) printf("12\n");
else if(n==) printf("60\n");
else
{
if((n&)==) cout<<cal(n)<<endl;
else cout<<n*(n-)*(n-)<<endl;
}
return ;
}

AC代码

acdream LCM Challenge (最小公倍数)的更多相关文章

  1. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  2. [codeforces 235]A. LCM Challenge

    [codeforces 235]A. LCM Challenge 试题描述 Some days ago, I learned the concept of LCM (least common mult ...

  3. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

  4. A - LCM Challenge

    A - LCM Challenge Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others ...

  5. 求gcd(最大公因数),lcm(最小公倍数)模板

    gcd(最大公因数),lcm(最小公倍数) #include<iostream> using namespace std; int gcd(int a,int b)//辗转相除法(欧几里德 ...

  6. [CF235A] LCM Challenge - 贪心

    找到3个不超过n的正整数(可以相同),使得它们的lcm(最小公倍数)最大. Solution 可以做得很优雅吧,但我喜欢(只会)暴力一点 根据质数密度分布性质,最后所取的这三个数一定不会比 \(n\) ...

  7. acd LCM Challenge(求1~n的随意三个数的最大公倍数)

    Problem Description Some days ago, I learned the concept of LCM (least common multiple). I've played ...

  8. GCD(最大公约数)和LCM(最小公倍数)的求法

    GCD(最大公约数) (1)辗转相除法(欧几里得算法)(常用) 将两个数a, b相除,如果余数c不等于0,就把b的值给a,c的值给b,直到c等于0,此时最大公约数就是b (2)更相减损术 将两个书中较 ...

  9. BNU 12846 LCM Extreme 最小公倍数之和(线性欧拉筛选+递推)

    LCM Extreme Time Limit: 3000ms Memory Limit: 131072KB   This problem will be judged on UVALive. Orig ...

随机推荐

  1. OS/400相关介绍

    OS/400是IBM公司为其AS/400以及AS/400e系列商业计算机开发的操作系统,由于OS/400的设计充分考虑了AS/400的硬件设计,而且通常作为AS/400的一个基本组件被提供,因此几乎没 ...

  2. C++程序员笔试复习概要(一)

    第8章     类和对象的创建 [内容提要] 类和对象 构造函数和析构函数 对象数组与对象指针 静态成员 友元 静态函数 虚函数 [重点与难点] 8.1 类和对象 8.1.1 类的定义 类实质上是用户 ...

  3. Failed to execute command: ""C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ResGen.exe" 的一个解决办法

    最近在做wpf项目,期间下了一些源码参考,但是在build时经常遇到下面这种bug: Error 2 Failed to execute command: ""C:\Program ...

  4. raise_application_error用法

    我们经常通过dbms_output.put_line来输出异常信息,但有时需要把异常信息返回给调用的客户端.此时我们用raise_application_error,允许用户在pl/sql中返回用户自 ...

  5. vi使用教程

    Vi有3种模式: 命令模式——命令操作 插入模式——进入vi之后,输入i/a/o,按Esc键,进入命令模式 编辑模式——:set nu, 以回车结束 1.插入 a - 光标后插入 A - 本行末尾插入 ...

  6. springmvc整合redis架构搭建实例

    新换环境,又有新东西可以学习了,哈皮! 抽空学习之余看了一下redis,个人对Springmvc的爱是忠贞不渝,所以整理了一下Springmvc整合redis的环境搭建.分享学习. 第一步: 创建ma ...

  7. nodejs phantom add click event

    page.evaluate( function() { // find element to send click to var element = document.querySelector( ' ...

  8. 【贪心】 BZOJ 3252:攻略

    3252: 攻略 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 261  Solved: 90[Submit][Status][Discuss] De ...

  9. Educational Codeforces Round 5 A

    Problem A:http://codeforces.com/contest/616/problem/A A. Comparing Two Long Integers 果然还是我太天真了(长整数比较 ...

  10. NYOJ 题目15 括号匹配(二)(区间DP)

    点我看题目 题意 : 中文题不详述. 思路 : 本来以为只是个小模拟,没想到是个区间DP,还是对DP不了解. DP[i][j]代表着从字符串 i 位置到 j 位置需要的最小括号匹配. 所以初始化的DP ...