[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. 【niubi-job——一个分布式的任务调度框架】----如何开发一个niubi-job的定时任务

    引言 上篇文章LZ主要讲解了niubi-job如何安装,如果看过上一篇文章的话,大家应该知道,niubi-job执行的任务是需要用户自己上传jar包的. 那么问题来了,这个jar包如何产生?有没有要求 ...

  2. Nginx 配置详解

    http://www.cnblogs.com/analyzer/articles/1377684.html 本文转自:http://blog.c1gstudio.com/archives/434 推荐 ...

  3. java.io.stream

    1. package com.io.Stream; import java.io.*; public class NyFileInputStream1 { /** * 读取文件的streamIO * ...

  4. User Attributes - Inside Active Directory

    User Attributes - Inside Active Directory Related to the book Inside Active Directory, ISBN 0-201-61 ...

  5. JMeter工具的使用-ForEach

    1,Add Thread group this detail information about this panel as below link http://jmeter.apache.org/u ...

  6. .map文件的作用以及在chorme下会报错找不到jquery-1.10.2.min.map文件,404 的原因

    source map文件是js文件压缩后,文件的变量名替换对应.变量所在位置等元信息数据文件,一般这种文件和min.js主文件放在同一个目录下. 比如压缩后原变量是map,压缩后通过变量替换规则可能会 ...

  7. 【CodeForces 297C】Splitting the Uniqueness

    题意 序列s有n个数,每个数都是不同的,把它每个数分成两个数,组成两个序列a和b,使ab序列各自去掉个数后各自的其它数字都不同. 如果存在一个划分,就输出YES,并且输出两个序列,否则输出NO. 分析 ...

  8. 学习笔记-KMP算法

    按照学习计划和TimeMachine学长的推荐,学习了一下KMP算法. 昨晚晚自习下课前粗略的看了看,发现根本理解不了高端的next数组啊有木有,不过好在在今天系统的学习了之后感觉是有很大提升的了,起 ...

  9. 51NOD 1400 序列分解

    传送门:1400 序列分解序列分解 基准时间限制:1s  空间限制:131072 KBKB131072 KB 1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题1 秒 空间限制:13 ...

  10. Spring学习1-初识Spring

    一.简介   1.Spring是一个开源的控制反转(Inversion of Control ,IoC)和面向切面(AOP)的容器框架.它的主要目得是简化企业开发.  2.为何要使用Spring?   ...