zoukankan      html  css  js  c++  java
  • 51 Nod 1419 最小公倍数挑战

                               1419 最小公倍数挑战

    几天以前,我学习了最小公倍数。玩得挺久了,想换换口味。

    我不想用太多的数字,我想从1到n中选三个数字(可以相同)。使得他们的最小公倍数最大。

    Input
    单组测试数据。
    第一行有一个整数n (1≤n≤1,000,000)。
    Output
    输出一个整数表示选三个数字的最大的最小公倍数。
    Input示例
    9
    7
    Output示例
    504
    210

    思路:任意的两个相邻自然数肯定互质 任意两个相邻的奇数肯定互质
       当 n 为奇数时 n 和 n-1肯定互质 n-1 和 n-2 肯定互质 n 和 n-2 也互质
       所以 LCM 为 n*(n-1)*(-2)
       当 n 为 偶数时 n 和 n-1 肯定互质 考虑 和 n-3 的关系 如果和 n-3 也互质的话 LCM 就是 n*(n-1)*(n-3)
         如果 和 n-3 不互质 只能 将 n 向后移一位 否则 LCM不是最大 这时候输出 (n-1)*(n-2)*(n-3)
     1 #include <cstdio>
     2 #include <cctype>
     3 
     4 typedef unsigned long long LL;
     5 
     6 LL n;
     7 
     8 int hh() {
     9     scanf("%lld",&n);
    10     
    11     if(n<=2) {
    12         printf("%lld
    ",n);
    13         return 0;
    14     }
    15     
    16     if(n&1) printf("%lld
    ",(LL)n*(n-1)*(n-2));
    17     else {
    18         if(n%3==0) printf("%lld
    ",(LL)(n-1)*(n-2)*(n-3));
    19         else printf("%lld
    ",(LL)n*(n-1)*(n-3));
    20     } 
    21     
    22     return 0;
    23 }
    24 
    25 int sb=hh();
    26 int main(int argc,char**argv) {;}
    代码
     
  • 相关阅读:
    js基础面试篇
    vue自定义指令
    vue兄弟节点通信
    vue----打包上线引用外部cdn
    vue----mockjs
    laravel database opearate1
    laravel seeding
    backtotop组件
    配置节流函数
    failed at the chromedriver@2.33.2 install script
  • 原文地址:https://www.cnblogs.com/whistle13326/p/7731902.html
Copyright © 2011-2022 走看看