[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. Sublime Text 3使用参考手册

    什么是Sublime Text? Sublime Text 是一个代码编辑器(Sublime Text 2是收费软件,但可以无限期试用),也是HTML和散文先进的文本编辑器.Sublime Text是 ...

  2. 《TCP/IP详解卷1:协议》第17、18章 TCP:传输控制协议(2)-读书笔记

    章节回顾: <TCP/IP详解卷1:协议>第1章 概述-读书笔记 <TCP/IP详解卷1:协议>第2章 链路层-读书笔记 <TCP/IP详解卷1:协议>第3章 IP ...

  3. AngularJS - 服务简介

    服务是AngularJS中非常重要的一个概念,虽然我们有了控制器,但考虑到其生命实在脆弱,我们需要用到服务. 起初用service时,我便把service和factory()理所当然地关联起来了. 确 ...

  4. Ibatis学习总结3--SQL Map XML 映射文件

    在前面的例子中,只使用了 SQL Map 最简单的形式.SQL Map 的结构中还有其他更多 的选项.这里是一个 mapped statement 较复杂的例子,使用了更多的特性. <sqlMa ...

  5. 3.3.1实现Servlet

    FirstServlet.java package com.helloweenvsfei.servlet; import java.io.IOException; import java.io.Pri ...

  6. java.lang.NoClassDefFoundError: com/sun/mail/util/BEncoderStream

    :java.lang.NoClassDefFoundError: com/sun/mail/util/BEncoderStream 这个问题是Mail.jar包没有引入到java路径中,或者是版本的问 ...

  7. iOS边练边学--多线程练习的多图片下载 以及 使用第三方框架(SDWebImage)的多图片下载

    一.自己实现多图片下载应该注意的问题 沙盒缓存的问题 程序缓存的问题 cell重复利用显示图片混乱的问题 -- 用户拖拽快,下载图片慢导致的 解决图片混乱引入NSOperation集合的问题 资源下载 ...

  8. Java基础-JVM堆与栈

    首先看一个解析列子 JVM的内存空间: (1). Heap 堆空间:分配对象 new Student() (2). Stack 栈空间:临时变量 Student stu (3).Code 代码区 :类 ...

  9. php环境搭建工具包推荐

    如题,无论是生产还是测试环境,推荐一下这个: http://www.phpstudy.net/ 同时,也是一个php学习的网站,和w3cschool差不错,但是这里只有php.

  10. [NOIP2011] 提高组 洛谷P1003 铺地毯

    题目描述 为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有 n 张地毯,编号从 1 到n .现在将这些地毯按照编号从小到大的顺序平行于 ...