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. IOS 加载网络图片2

    //1. NSData dataWithContentsOfURL // [self.icon setImage:[UIImage imageWithData:[NSData dataWithCont ...

  2. C#里面Auotpostback回刷时候,textbox里面的password怎么保存

    刷新页面时,如何保留页面上的PassWord模式下的TextBox的值? this.txtUserPwd.Attributes["value"] = txtUserPwd.Text ...

  3. UNIX基础--Manual Pages

    联机手册 Manual Pages 最详细的使用说明文档莫过于 FreeBSD 里的联机手册了. 几乎每一个程序都会附上一份简短说明, 以介绍这个程序的的基本功能以及参数的用法. 我们能通过 man ...

  4. 用微软makecert.exe生成一个自签名的证书

    RT makecert.exe不用去找,安装VS2008后,在开始菜单相应的路径找到该命令提示符:Microsoft Visual Studio 2008/Visual Studio Tools/Vi ...

  5. no method declared with objective-c selector error

    down voteaccepted Swift 2.2 / Xcode 7.3 has a new way to use selector:Selector("funcName") ...

  6. HttpHelps类

    /// <summary> /// 类说明:HttpHelps类,用来实现Http访问,Post或者Get方式的,直接访问,带Cookie的,带证书的等方式,可以设置代理 /// 重要提示 ...

  7. HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online)

    HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online) 题目链接http://acm.hdu.edu.cn/showp ...

  8. Maven中央(或国内)仓库地址

    maven官方 http://repo1.maven.org/maven2/  或 http://repo2.maven.org/maven2/ (延迟低一些) osc 本家 http://maven ...

  9. stm32 串口乱码的解决

    版权声明:本文为博主原创文章. 前几天在中移物联网申请了一个迷你开发板,运行官方提供的程序,感觉板子是正常的.但是自己写的程序能够刷到板子上,但是串口却是乱码.官方和我的额程序都是用的库函数的方式写的 ...

  10. jfinal获取服务器的IP和端口

    String serverIp = getRequest().getServerName(); Integer serverPort = getRequest().getServerPort();