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. python 判断 windows 隐藏文件/系统文件

    linux 下隐藏文件是以句号 “.” 开头的文件,根据文件名即可判断是否为隐藏文件. win 下是以文件隐藏属性确定的,所以,只能通过微软的 API 获取隐藏属性来判断是否为隐藏文件. 1. win ...

  2. Django配置静态文件(CSS\js)及Django调用JS、CSS、图片等静态文件

    1 新建一项目: root@python:django-admin.py startproject csstest root@python:cd csstest root@python:ls csst ...

  3. Linux进程间通信IPC学习笔记之消息队列(SVR4)

    Linux进程间通信IPC学习笔记之消息队列(SVR4)

  4. 2015-4-2的阿里巴巴笔试题:乱序的序列保序输出(bit数组实现hash)

    分布式系统中的RPC请求经常出现乱序的情况.写一个算法来将一个乱序的序列保序输出.例如,假设起始序号是1,对于(1, 2, 5, 8, 10, 4, 3, 6, 9, 7)这个序列,输出是:123, ...

  5. C++ 虚函数表解析(转载)

    转载自:陈皓 http://blog.csdn.net/haoel/article/details/1948051/ 前言 C++中的虚函数的作用主要是实现了多态的机制.关于多态,简而言之就是用父类型 ...

  6. Qt的gzip模块实现

    一直没找到Qt中方便的gzip模块,于是自己动手,调用zlib模块实现了一份. 目标:  1.gzip的压缩与解压 2.内存中操作 3.方便的Qt接口   实现分析: gzip 压缩算法为 defla ...

  7. unity手游之聊天SDK集成与使用二

    集成思路 如果是自己的小游戏的话,可以把好友等信息直接保存在亲加服务器上,通过调用api来操作. 我们游戏只使用sdk的通信功能,好友等信息保存在自己的服务器上. 用户在登陆游戏的时候,通过算法用用户 ...

  8. python 知识 rstrip,strip,lstrip

    rstrip,strip,lstrip 作用:去除字符串中的空格或指定字符 一.默认用法:去除空格str.strip()  : 去除字符串两边的空格str.lstrip() : 去除字符串左边的空格s ...

  9. [原创] zabbix学习之旅一:源码安装

    zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统管理员快速定位/解决存 ...

  10. linux上很方便的上传下载文件工具rz和sz

    linux上很方便的上传下载文件工具rz和sz(本文适合linux入门的朋友) ##########################################################&l ...