A. LCM Challenge

题目连接:

http://www.codeforces.com/contest/235/problem/A

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 ≤ 106) — 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

Hint

题意

从1到n中选3个数,然后要求使得这三个数的lcm最大,问你这个lcm是多少

题解:

大胆猜想,不用证明

这三个数显然离n的距离不是很大,因为显然在某个区间内,存在三个互质的数,这三个数乘起来就好了

所以我们随便设一个下界然后跑就好了

代码

#include<bits/stdc++.h>
using namespace std; long long gcd(long long a,long long b)
{
if(b==0)return a;
return gcd(b,a%b);
}
int k = 100;
long long solve(long long a,long long b,long long c)
{
long long tmp = a*b/gcd(a,b);
tmp = tmp*c/gcd(tmp,c);
return tmp;
}
int main()
{
long long ans = 0;
int n;
scanf("%d",&n);
for(int i=n;i>=n-k&&i>=1;i--)
for(int j=n;j>=n-k&&j>=1;j--)
for(int t=n;t>=n-k&&t>=1;t--)
ans=max(ans,solve(i,j,t));
cout<<ans<<endl;
}

Codeforces Round #146 (Div. 1) A. LCM Challenge 水题的更多相关文章

  1. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  2. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  3. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  4. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  5. Codeforces Round #335 (Div. 2) B. Testing Robots 水题

    B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...

  6. Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

    A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...

  7. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  8. Codeforces Round #188 (Div. 2) A. Even Odds 水题

    A. Even Odds Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/ ...

  9. Codeforces Round #333 (Div. 2) A. Two Bases 水题

    A. Two Bases Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/602/problem/ ...

随机推荐

  1. Maps

    Maps.uniqueIndex()将列表转换为map  //iterator各个元素作为Map.values, key为Function.apply返回值 Maps.uniqueIndex(ps.i ...

  2. hdu 2602 Bone Collector(01背包)

    题意:给出包裹的大小v,然后给出n块骨头的价值value和体积volume,求出一路下来包裹可以携带骨头最大价值 思路:01背包 1.二维数组(不常用 #include<iostream> ...

  3. Mac OS X 10.9 编译C++11

    Notice: How to compile C++ with C++ 11 support in Mac Terminal stackoverflow上面的问题 其实mac里面的不是g++而是cla ...

  4. 机器学习中的算法-决策树模型组合之随机森林与GBDT

    机器学习中的算法(1)-决策树模型组合之随机森林与GBDT 版权声明: 本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com, 本文可以被全部的转载或者部分使 ...

  5. sendip简单使用

    sendip是linux下一个比较好用的发包软件,简单记录一下它的用法 下载源码,编译安装后,可通过  man sendip,查看具体选项介绍,其中说明sendip支持的协议包括:ipv4 ipv6 ...

  6. WCF綁定

    服务之间的通信方式是多种多样的,有多种可能的通信模式.包括:同步的请求与应答(Request/Reply)消息,或者异步的即发即弃(Fire-and-Forget)消息等等,在通信时传输的消息编码格式 ...

  7. mongodb地理空间索引原理阅读摘要

    http://www.cnblogs.com/taoweiji/p/3710495.html 具体原理在上面 简单概述,(x,y)经纬度坐标,通过geohash的方式,通过N次方块四分割生成一个坐标码 ...

  8. focus与定位

    <html> <head> <script type="text/javascript" src="/jquery/jquery.js&qu ...

  9. Android Studio 中SDK Manager的设置

    android studio 代码块左边的缩进对齐线的颜色修改:  Settings -> Editor -> Colors & Fonts -> General -> ...

  10. Chocolatey的安装与使用

    @(编程) 前言 在 Linux 下,大家喜欢用 apt-get 来安装应用程序,如今在 windows 下,大家可以使用 Chocolatey 来快速下载搭建一个开发环境. Chocolatey 的 ...