acd LCM Challenge(求1~n的随意三个数的最大公倍数)

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 thann. 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
仅仅要这三个数中有两个数是奇数一个是偶数,最小公倍数就是这三个数的积。
#include<stdio.h>
int main()
{
    long long  LCM,n;
    while(scanf("%lld",&n)>0)
    {
        if(n==1)LCM=1;
        if(n==2)LCM=2;
        if(n>2)
        {
            if(n%2)LCM=n*(n-1)*(n-2);
            else
            {
                if(n*(n-1)*(n-2)/2<n*(n-1)*(n-3))
                    LCM=n*(n-1)*(n-3);
                else LCM=n*(n-1)*(n-2)/2;
            }
        }
        printf("%lld\n",LCM);
    }
}

acd LCM Challenge(求1~n的随意三个数的最大公倍数)

时间: 2024-10-25 17:40:15

acd LCM Challenge(求1~n的随意三个数的最大公倍数)的相关文章

acd LCM Challenge(求1~n的任意三个数的最大公倍数)

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

HUST_ACdream区域赛指导赛之手速赛系列(1)(2)F——GCD+1ll——LCM Challenge

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 do

A - LCM Challenge

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 w

ACdream1077:LCM Challenge

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

acdream LCM Challenge (最小公倍数)

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

HDU4622:Reincarnation(后缀数组,求区间内不同子串的个数)

Problem Description Now you are back,and have a task to do: Given you a string s consist of lower-case English letters only,denote f(s) as the number of distinct sub-string of s. And you have some query,each time you should calculate f(s[l...r]), s[l

[华为机试练习题]45.求某二进制数中1的个数

题目 描述: 题目标题: 求某二进制数中1的个数. 给定一个unsigned int型的正整数,求其二进制表示中"1"的个数,要求算法的执行效率尽可能地高. 详细描述: 原型: int GetCount(unsigned int num) 输入参数: num 给定的正整数 输出参数(指针指向的内存区域保证有效): 无 返回值: 返回1的个数 举例: 输入13,则对应的二进制是1101,那么1的个数为3个.则:返回3. 练习阶段: 初级 代码 /*--------------------

第2章 数字之魅——求二进制中1的个数

求二进制中1的个数 问题描述 对于一个字节(8bit)的变量,求其二进制表示中“1”的个数,要求算法的执行效率尽可能地高. [解法一] 可以举一个八位的二进制例子来进行分析.对于二进制操作,我们知道,除以一个2,原来的数字将会减少一个0.如果除的过程中有余,那么就表示当前位置有一个1. 以10 100 010为例: 第一次除以2时,商为1 010 001,余为0. 第二次除以2时,商为101 000,余为1. 因此,可以考虑利用整型数据除法的特点,通过相除和判断余数的值来进行分析.于是有了如下的

算法题:求数组中最小的k个数

说明:本文仅供学习交流,转载请标明出处,欢迎转载! 题目:输入n个整数,找出其中最小的k个数. <剑指offer>给出了两种实现算法: 算法1:采用Partition+递归法,该算法可以说是快速排序和二分查找的有机结合.算法的时间复杂度为O(n),缺点在于在修改Partition的过程中会修改原数组的值. 算法2:采用top-k算法.如果要找最小的K个数,我们才用一个含有K个值的大顶堆:如果要找最大的K个数,我们采用小顶堆.该算法的时间复杂度为O(nlogK),是一种比较好的算法,启发于堆排序