[codeforces 235]A. LCM Challenge

试题描述

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?

输入

The first line contains an integer n (1 ≤ n ≤ 106) — the n mentioned in the statement.

输出

Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.

输入示例


输出示例


数据规模及约定

见“输入

题解

对于奇数,那么显然答案是 lcm(n, n-1, n-2),对于偶数,答案只可能是这两种:

1. lcm(n, n-1, n-3)

2. lcm(n-1, n-2, n-3)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define LL long long
int n; LL gcd(LL a, LL b) { return !b ? a : gcd(b, a % b); }
LL lcm(LL a, LL b) { return a * b / gcd(a, b); } int main() {
n = read(); if(n == 1) return puts("1"), 0;
if(n & 1) return printf("%I64d\n", (LL)n * (n - 1) * (n - 2)), 0;
int a1 = n - 3, b1 = n - 1, c1 = n;
int a2 = n - 3, b2 = n - 2, c2 = n - 1;
printf("%I64d\n", max(lcm(lcm(a1, b1), c1), lcm(lcm(a2, b2), c2))); return 0;
}

[codeforces 235]A. LCM Challenge的更多相关文章

  1. Codeforces 235 E Number Challenge

    Discription Let's denote d(n) as the number of divisors of a positive integer n. You are given three ...

  2. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

  3. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  4. acdream LCM Challenge (最小公倍数)

    LCM Challenge Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others) Su ...

  5. A - LCM Challenge

    A - LCM Challenge Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others ...

  6. 【codeforces 235E】 Number Challenge

    http://codeforces.com/problemset/problem/235/E (题目链接) 题意 给出${a,b,c}$,求${\sum_{i=1}^a\sum_{j=1}^b\sum ...

  7. codeforces 235 div2 C Team

    题目:http://codeforces.com/contest/401/problem/C 题意:n个0,m个1,求没有00或111的情况. 这么简单的题..... 做题的时候脑残了...,今天,贴 ...

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

    Problem Description Some days ago, I learned the concept of LCM (least common multiple). I've played ...

  9. [CF235A] LCM Challenge - 贪心

    找到3个不超过n的正整数(可以相同),使得它们的lcm(最小公倍数)最大. Solution 可以做得很优雅吧,但我喜欢(只会)暴力一点 根据质数密度分布性质,最后所取的这三个数一定不会比 \(n\) ...

随机推荐

  1. #Linux学习笔记# Linux文件的所有者、群组和其他人

    1.关于所有者.群组和其他人 在Linux系统中,每个文件都具有User.Group和Others三种身份的权限配置.那这三种身份分别表示什么意思呢?配置这三种身份的权限有啥意义呢? (1)文件所有者 ...

  2. Git.Framework 框架随手记--ORM条件组合

    在上一篇<Git.Framework 框架随手记--ORM新增操作>中简单记录了如何对数据进行删除和修改,其用法都非常简单,在文章中提到了Where()方法,本文将详述Where() 等条 ...

  3. Pivot的SelectionChanged事件绑定到VM的Command

    我要实现的是页面加载时,只获取SelectedIndex=0的数据,然后根据Pivot的SelectionChanged动态获取其他项的数据,我用的是MVVM的Command的方式,不想用后台注册事件 ...

  4. 今天学习到的关于mysql数据库的linux命令

    1. 登录mysql数据库: mysql -uroot -p 2.安装会提示的mysql的数据库软件:mycli sudo apt-get install mycli 3.安装依赖包: sudo ap ...

  5. linux 添加永久ip、路由和开启路由功能

    一.添加永久ip 编辑/etc/sysconfig/network-scripts/ifcfg-eth0文件: 网络接口配置文件 [root@localhost ~]# cat /etc/syscon ...

  6. FZU5BOYS-Beta版本冲刺计划及安排

    1.下一阶段需要改进完善的功能 话题模块(分类参考Citeulike论文网站),文章/计划的删除功能 2.下一阶段新增的功能 1)推荐模块(冷启动问题,拟爬取部分豆瓣数据,部分伪专家数据(我们团队), ...

  7. hdu4547 lca tarjan

    比较直接. #include<map> #include<queue> #include<stack> #include<cmath> #include ...

  8. Spring 管理数据源

    Spring 管理数据源 不管通过何种持久化技术,都必须通过数据连接访问数据库,在Spring中,数据连接是通过数据源获得的.在以往的应用中,数据源一般是Web应用服务器提供的.在Spring中,你不 ...

  9. RBAC(基于角色的访问控制权限)表结构

    Rbac 支持两种类,PhpManager(基于文件的) 和 DbManager(基于数据库的) 权限:就是指用户是否可以执行哪些操作 角色:就是上面说的一组操作的集合,角色还可以继承 在Yii2.0 ...

  10. Oracle新建数据库(新用户)

    1.首先,创建(新)用户: create user username identified by password; username:新用户名的用户名 password: 新用户的密码也可以不创建新 ...