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 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,求不大于n的三个数的公共的最小公倍数,check小于等于3的情况,else 分成奇偶,因为奇数时,n和n-2都是奇数,肯定是互质的,如果是偶数的话那就是三种情况里面的最大值

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int GCD(long  a,long  b){
    return b == 0 ? a : GCD(b, a % b);
}
int main()
{
    int n;
    while(~scanf("%d",&n)){
    if(n == 1)
        printf("1\n");
    else if(n == 2)
        printf("2\n");
    else if(n == 3)
        printf("6\n");
    else {
        if((n % 2) == 1)
        printf("%lld\n",1ll*n*(n-1)*(n-2));
        else {
            long long max1 = 0;
            max1 = max(max1,1ll*(n-1)*(n-2)*(n-3));
            max1 = max(max1,1ll*n*(n-1)*(n-3)/GCD(n,n-3));
            max1 = max(max1,1ll*n*(n-1)*(n-2)/GCD(n,n-2));
            printf("%lld\n",max1);
            }
        }
    }
    return 0;
}

GCD写法:

int GCD(long  a,long  b){
    return b == 0 ? a : GCD(b, a % b);
}
 
时间: 2024-10-23 08:32:50

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

HUST_ACdream区域赛指导赛之手速赛系列(1)(2)G——BFS——Cutting Figure

Description You've gotten an n × m sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as A. Set A is connected. Your task is to find the minimum number of squares that we can delete from set A to make i

HUST_ACdream区域赛指导赛之手速赛系列(1)(2)D——数学——Triangles

Description 已知一个圆的圆周被  N 个点分成了 N 段等长圆弧,求任意取三个点,组成锐角三角形的个数. Input 多组数据. 每组数据一个N (N ≤  1000000). Output 对于每组数据,输出不同锐角三角形的个数. Sample Input 3 4 5 Sample Output 1 0 5大意:数学推导,分成奇数点偶数点讨论偶数时:只要两个相减就是答案奇数时同理:还有1ll*涨姿势用来变成long long 形式 #include<cstdio> #includ

ACdream区域赛指导赛之手速赛系列(5) 题解

A - Problem A Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description The decimal numeral system is composed of ten digits, which we represent as "0123456789" (the digits in a system are

ACdream区域赛指导赛之手速赛系列(7)

A - Dragon Maze Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus 题目连接:     传送门 Problem Description You are the prince of Dragon Kingdom and your kingdom is in danger of running out of power. You must find

ACdream区域赛指导赛之手速赛系列(6)

Problem Description Sudoku is a popular single player game. The objective is to fill a 9x9 matrix with digits so that each column, each row, and all 9 non-overlapping 3x3 sub-matrices contain all of the digits from 1 through 9. Each 9x9 matrix is par

快速切题 acdream手速赛(6)A-C

Sudoku Checker Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description Sudoku is a popular single player game. The objective is to fill a 9x9 matrix with digits so that each colu

Acdream手速赛7

蛋疼啊,本次只做出了一道题目...渣爆了... 妈蛋,,卡题之夜..比赛结果是1道题,比赛完哗啦哗啦出4道题.. A acdream1191 Dragon Maze 题意: 给一个迷宫,给出入口坐标和出口坐标,要求从入口到出口的步数尽可能少,如果有多种方案,则要求获得的分数尽可能多,获得的分数为经过的方格的数字之和 思路: bfs求最小步数,每走一步更新一下走到这个格子的最大权值 #include <bits/stdc++.h> using namespace std; typedef lon

Java制作最难练手速游戏,Faker都坚持不了一分钟

想练手速,来啊,互相伤害啊 Java制作最难练手速游戏,目测Faker也坚持不了一分钟 制作思路:只靠Java实现.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java. 字母模型应该是整个游戏的主角,因为整个游戏过程中都涉及到它的运动,比如坠落,消失,产生等,首先应该考虑字母随即出现的位置,在游戏中不断下落,计算下落的高

猫和老鼠 蓝桥杯/手速/暴力练习赛(暴力搜索)

猫和老鼠 蓝桥杯/手速/暴力练习赛 [题目描述] 猫和老鼠在10*10 的方格中运动,例如: *...*..... ......*... ...*...*.. .......... ...*.C.... *.....*... ...*...... ..M......* ...*.*.... .*.*...... C=猫(CAT) M=老鼠(MOUSE) *=障碍物 .=空地 猫和老鼠每秒中走一格,如果在某一秒末他们在同一格中,我们称他们“相遇”. 注意,“对穿”是不算相遇的.猫和老鼠的移动方式相