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. C#基础--属性

    定义一个Book类: namespace ConsoleTest { public class Book { private string _bookIsbn; private string _boo ...

  2. python流程控制:while循环

    python编程中whihe语句用于循环执行程序,即在某条件下,循环执行某段程序,以处理需要重复处理的相同任务. while循环语句格式: while <判断条件>: 执行语句 count ...

  3. LVM

    LVM (简体中文) pvdisplay -v -m命令查看物理分段 Create logical volume from another LV free space PVMOVE(8)

  4. [SOJ] 导游

    Description Mr. G. 在孟加拉国的一家旅游公司工作.他当前的任务是带一些游客去一些遥远的城市.和所有国家一样,一些城市之间有双向道路.每对相邻城市之间都有一条公交路线,每条路线都规定了 ...

  5. 常用网页标签重置CSS

    做前端开发时常需要将网页中所有标签的格式清空,从而使各个浏览器标签样式一样.以下是网络上常见的CSS代码 /* =s Reset (by YUI 3) */ html{color:#000;} bod ...

  6. php 便利数组方法

    数组在PHP中是一个非常强大的武器,用起来方便.容易,由于使用起来异常灵活,用它就可以实现数据结构中的链表.栈.队列.堆以及所谓的字典.集合等,也可以转换成XML格式. 1.使用for for语句遍历 ...

  7. css,js零散知识的整理

    在同一个dom上以冒泡和捕获的方式绑定一个事件,如果事件源是该元素,则是先绑定的哪一个就先执行哪一个,事件源是dom的子孙节点,则先执行捕获事件

  8. sql第一天

    关系数据库中的关系指的就是表 table 表   Column 列   Field 字段   Row 行 非空约束  not null 主键约束(PK)primary key constraint 唯 ...

  9. HDU 3294 Girls' research

    题目地址 manacher #include<cstdio> #include<string.h> #include<algorithm> using namesp ...

  10. Mysql存储过程和函数

    Mysql存储过程和函数 基本概念: 创建存储过程和函数是指将经常使用的一组SQL语句的组合在一起,并将这些SQL语句当作一个整体存储在MySQL服务器中.例如,银行经常需要计算用户的利息.不同类别的 ...