博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
acdream LCM Challenge (最小公倍数)
阅读量:4639 次
发布时间:2019-06-09

本文共 2021 字,大约阅读时间需要 6 分钟。

 

        LCM Challenge

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

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之后肯定是奇数了,用奇数的方法。

 

 

1 /* 2 * this code is made by xcw0754 3 * Problem: 1077 4 * Verdict: Accepted 5 * Submission Date: 2015-07-16 10:24:02 6 * Time: 0MS 7 * Memory: 1672KB 8 */ 9 #include 
10 #define LL long long11 #define pii pair
12 #define INF 0x7f7f7f7f13 using namespace std;14 const int N=200000+50;15 16 LL cal(LL n) //偶数17 {18 LL ans=0;19 //n n-1 n-320 if(__gcd(n,n-3)==1) ans=max(ans, n*(n-1)*(n-3));21 22 //n-1 n-2 n-323 ans=max(ans, (n-1)*(n-2)*(n-3));24 25 return ans;26 }27 28 29 int main()30 {31 //freopen("input.txt", "r", stdin);32 LL n;33 scanf("%lld",&n);34 if(n==1) printf("1\n");35 else if(n==2) printf("2\n");36 else if(n==3) printf("6\n");37 else if(n==4) printf("12\n");38 else if(n==5) printf("60\n");39 else40 {41 if((n&1)==0) cout<
<
AC代码

 

转载于:https://www.cnblogs.com/xcw0754/p/4650776.html

你可能感兴趣的文章
jquery控制css的display(控制元素的显示与隐藏)
查看>>
关于python做人工智能的一个网页(很牛逼)
查看>>
判断控件的CGRect是否重合,获取控件的最大XY值
查看>>
POJ-1128 Frame Stacking
查看>>
异常体系
查看>>
String.format(转)
查看>>
解决 CS0006 未能找到元数据文件
查看>>
HDU 5131.Song Jiang's rank list (2014ACM/ICPC亚洲区广州站-重现赛)
查看>>
mysql搭建主从数据库
查看>>
新的一年,新的开始
查看>>
python模块struct
查看>>
图像的灰度级和动态范围(转)
查看>>
C# MODBUS协议 上位机(转)
查看>>
CSS box-shadow 属性
查看>>
vue:图片切换动态显示
查看>>
备忘录
查看>>
软件工程个人作业02
查看>>
pip install 问题
查看>>
vue-router导航守卫,限制页面访问权限
查看>>
2019 Multi-University Training Contest 1 - 1012 - NTT
查看>>