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-10 13:05:48

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

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

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

求数组中和为给定值的任意两个数

转载请注明出处:http://blog.csdn.net/ns_code/article/details/24933341     题目: 输入一个已经按升序排序过的数组和一个数字,在数组中查找两个数,使得它们的和正好是输入的那个数字.要求时间复杂度是O(n).如果有多对数字的和等于输入的数字,输出任意一对即可. 例如输入数组1.2.4.7.11.15和数字15.由于4+11=15,因此输出4和11.     思路: 最直接的做法是暴力法,两个for循环,时间复杂度为O(n*n),但是这样没有充

求数组中任意两个数之间所有数字的和

303. Range Sum Query - Immutable   求数组中任意两个数之间所有数字的和 QuestionEditorial Solution My Submissions Total Accepted: 37248 Total Submissions: 146945 Difficulty: Easy Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j),

hdoj 2196 Computer【树的直径求所有的以任意节点为起点的一个最长路径】

Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4440    Accepted Submission(s): 2236 Problem Description A school bought the first computer some time ago(so this computer's id is 1). Du

2.任意输入三个数,求最大数

(1)笨办法,采用if嵌套和&&判断,比较消耗资源,不过也能达到要求: #include<iostream> using namespace std; int main(){    int a,b,c,max;    cout<<"please input 3 numbers:"<<endl;    cin>>a>>b>>c;    if(a>b&&a>c)       

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