zoukankan      html  css  js  c++  java
  • 最大最小公倍数 (数学、贪心)

    Description

    已知一个正整数N,问从1~N中任选出三个数,他们的最小公倍数最大可以为多少。

    Input

    输入一个正整数N。

    Output

    输出一个整数,表示你找到的最小公倍数。

    Sample Input

    9

    Sample Output

    504

    HINT

    数据规模与约定
    1 <= N <= 106

    具体讲解参考:https://blog.csdn.net/ljd4305/article/details/21177485

    然后还有一点,不知道是不是数据的原因,就是我交题的时候,n不开long long会wa。。。

     1 #include <stdio.h>
     2 #include <iostream>
     3 #include <string>
     4 #include <string.h>
     5 #include <algorithm>
     6 #include <map>
     7 #include <vector>
     8 #include <set>
     9 #include <stack>
    10 #include <queue>
    11 #include <math.h>
    12 #include <sstream>
    13 using namespace std;
    14 typedef long long LL;
    15 const int INF=0x3f3f3f3f;
    16 const int maxn=1e5+10;
    17 const double eps = 1e-8;
    18 const double PI = acos(-1);
    19 
    20 int main()
    21 {
    22     #ifdef DEBUG 
    23     freopen("sample.txt","r",stdin);
    24     #endif
    25     
    26     LL n;
    27     scanf("%lld",&n);
    28     LL ans=n;
    29     if(n>=3)
    30     {
    31         if(n%2) ans=n*(n-1)*(n-2);
    32         else
    33         {
    34             if(n%3) ans=n*(n-1)*(n-3);
    35             else ans=(n-1)*(n-2)*(n-3);
    36         }
    37     }
    38     printf("%lld
    ",ans);
    39     
    40     return 0;
    41 }

    -

  • 相关阅读:
    linux常用命令
    练习00004
    python学习第六天
    练习00003
    练习00002
    python学习第四天
    练习00001
    Linux_安装mysql踩坑日记
    Linux_更改远程登录端口以及禁止root用户登录
    redis_基础_基本使用
  • 原文地址:https://www.cnblogs.com/jiamian/p/12388011.html
Copyright © 2011-2022 走看看