zoukankan      html  css  js  c++  java
  • A

    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)
     1 #include <stdio.h>
     2 int main()
     3 {
     4     long long n;
     5     while(scanf("%lld",&n)!=EOF)
     6     {
     7         if(n==1)printf("1
    ");
     8         else if(n==2)printf("2
    ");
     9         else if(n%2==1)/*奇数*/
    10         {
    11             printf("%lld
    ",n*(n-1)*(n-2));
    12         }
    13         else if(n%3==0)/*能被6整除*/
    14         {
    15             printf("%lld
    ",(n-1)*(n-2)*(n-3));
    16         }
    17         else    /*能被2整除*/
    18         {
    19             printf("%lld
    ",(n)*(n-1)*(n-3));
    20         }
    21     }
    22     return 0;
    23 }
    View Code
    转载请备注:
    **************************************
    * 作者: Wurq
    * 博客: https://www.cnblogs.com/Wurq/
    * Gitee: https://gitee.com/wurq
    **************************************
  • 相关阅读:
    古典密码-移位密码|埃特巴什密码Atbash
    古典密码-凯撒密码Caeser
    古典密码-维吉尼亚密码Vigenere
    使用kubeadm搭建一个k8s集群
    用户态线程和内核态线程的区别
    模板合集
    NoteExpress 章节合并后如何更新参考文献列表?
    CSDN 博客园主题
    GShang的博客园2020年终总结
    【比赛记录】CodeChef January Challenge 2021
  • 原文地址:https://www.cnblogs.com/Wurq/p/4455184.html
Copyright © 2011-2022 走看看