A - 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,让你从1~n中找出三个数,使他们的最大公倍数最大。(补充下小学五年级的知识:两个相临的奇数互质)
我们知道要是他们的最大公倍数最大,既为从最大的n,n-1,n-2开始查找,
  而且如果n为奇数的话,n*(n-1)*(n-2)=>奇数*偶数*奇数(且三个数互质),一定是所求最大的公倍数。
  如果n为偶数的话,则有两种情况:
  1,n能够被3整除;
  1,n不能够被3整除;
  因为n是偶数n*(n-1)*(n-2)=>偶数*奇数*偶数(且三个数不互质)<>不会是最大公倍数,   所以它的最大公倍数顶多为n*(n-1)*(n-3)=>偶数*奇数*奇数(此时三个数可能不互质),
  这里还需要判断的是n是否能够被3整除。
  为什么只考虑只能被3整除的情况呢?
  因为只有三个数,如果n能够被3整除的话,如果n能够被3整除的话,这三个数也便不互质了、
  它的最大公倍数不可能是为n*(n-1)*(n-3),因为n-3同样也能够被3整除,
  这么三个数也不互质,最大值顶多可能是n*(n-1)*(n-5)=>偶数*奇数*奇数(不一定互质)以及更小,
  或者为(n-1)*(n-2)*(n-3)=>奇数*偶数*奇数(且三个数互质),
  因为(n-1)*(n-2)*(n-3)-n*(n-1)*(n-5)
    =>(n-1)*{(n-2)*(n-3)-(n)*(n-5)}
    =>(n-1)*{(n*n-5*n)+6-(n*n-5*n)}
    =>(n-1)*6    
  因为n>=1所以(n-1)*(n-2)*(n-3)>n*(n-1)(n-5)  
  所以,当n为偶数,且能够被3整除的话,输出(n-1)*(n-2)*(n-3)
  否则输出(n)*(n-1)*(n-3)
 #include <stdio.h>
int main()
{
long long n;
while(scanf("%lld",&n)!=EOF)
{
if(n==)printf("1\n");
else if(n==)printf("2\n");
else if(n%==)/*奇数*/
{
printf("%lld\n",n*(n-)*(n-));
}
else if(n%==)/*能被6整除*/
{
printf("%lld\n",(n-)*(n-)*(n-));
}
else /*能被2整除*/
{
printf("%lld\n",(n)*(n-)*(n-));
}
}
return ;
}

A - 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. acdream LCM Challenge (最小公倍数)

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

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

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

  6. [CF235A] LCM Challenge - 贪心

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

  7. CF235A 【LCM Challenge】

    这题好毒瘤啊 (特别是long long的坑,调了半天没调好!!)先将你特判一下小于3的话直接输出就是惹,不是的话就判断一下它能不能被2整除如果不能就直接输出n*(n-1)*(n-2)否则进行枚举枚举 ...

  8. Codeforces Round #146 (Div. 2)

    A. Boy or Girl 模拟题意. B. Easy Number Challenge 筛素数,预处理出\(d_i\). 三重循环枚举. C. LCM Challenge 打表找规律. 若\(n\ ...

  9. ACdream区域赛指导赛之手速赛系列(2)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/DaiHaoC83E15/article/details/26187183        回到作案现场 ...

随机推荐

  1. mozilla your firefox profile cannot be loaded. it may be missing or inaccessible

    check the permissions ls -l ~/.cache | grep mozilla fix the permissions sudo chown -R $USER:$USER ~/ ...

  2. Python学习笔记——基础篇【第七周】———进程、线程、协程篇(socket基础)

    http://www.cnblogs.com/wupeiqi/articles/5040823.htmlhttp://i.cnblogs.com/EditPosts.aspx?postid=55437 ...

  3. MySql 安装过程(摘自网络)

    下面的是MySQL安装的图解,用的可执行文件安装的,详细说明了一下! 打开下载的mysql安装文件mysql-5.0.27-win32.zip,双击解压缩, 运行“setup.exe”,出现如下界面 ...

  4. Openjudge-NOI题库-字符串移位包含问题

    题目描述 Description 对于一个字符串来说,定义一次循环移位操作为:将字符串的第一个字符移动到末尾形成新的字符串. 给定两个字符串s1和s2,要求判定其中一个字符串是否是另一字符串通过若干次 ...

  5. 实现table中checkbox复选框、以及判断checked是否被选中、js操作checkedbox选中

    上图是实现效果. 下面贴代码 表的第一行也就是<th>中的代码,onclick事件是实现全选或者全不选效果. <th> <input id="allboxs&q ...

  6. 【转】CSS

    css概念 http://www.cnblogs.com/moveofgod/archive/2012/09/18/2691101.html css八大功能 http://developer.51ct ...

  7. iOS 加载本地 HTML 文件 CSS 样式图片无效果

    在开发的过程中,有时候需要加载一些 HTML 页面,对于不太复杂的界面,基本上都可以放到本地用 UIWebview 来加载,但是在开发过程中会碰到 UIWebview 加载出来的 HTML 页面没有图 ...

  8. ViewPagerIndicator的使用方法

    使用方法:   1.引用library,并解决support v4 jar包冲突   2.布局文件中添加viewpager和viewpagerindicator,布局文件: <LinearLay ...

  9. 当今Web应用的主要技术

    WWW是World Wide Web的简称,缩写为W3C,称为万维网,也简称为Web.目前Internet已经普及到整个社会,其中Web应用已经称为Internet上最受欢迎的应用之一,正是由于它的出 ...

  10. border表格有的自动换行,有的不能自动换行!

    解决手机端tab超过设置的宽度换行! <table id="vip-tab"> <tr id="leibie"> <th clas ...