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. Safari on iOS 7 中Element.getClientRects的Bug

    在Safari浏览器中,DOMElement和Range对象都提供了getBoundingClientRect方法和getClientRects方法.顾名思义,getBoundingClientRec ...

  2. 33条C#、.Net经典面试题目及答案

    33条C#..Net经典面试题目及答案[zt] 本文集中了多条常见的C#..Net经典面试题目例如".NET中类和结构的区别"."ASP.NET页面之间传递值的几种方式? ...

  3. Hadoop学习笔记1---简介 优点 架构分析

    一.Hadoop简介 Hadoop最早起源于Nutch.Nutch是一个开源的网络搜索引擎,由Doug Cutting于2002年创建.Nutch的设计目标是构建一个大型的全网搜索引擎,包括网页抓取. ...

  4. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. ajax 加载不同数据

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. dom 优酷得弹出

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. 第三百五十八天 how can I 坚持

    万事要有度,不要话唠,也不能不说,把握好分寸,今天貌似又说多了. 加了天班,理了个发,还有老爸明天来北京. 还有同学聚会没去,还有金龙让去吃鱼,没去. 还有.小米视频通话还行,能远程控制桌面, 还有, ...

  8. Hadoop Java开发实用快捷键收藏

    不断总结更新.... Alt  +  /    补全 Ctrl + T 打出结构 Ctrl + 2 ,再选择 Quick Assist - Assign to local variable  Ctrl ...

  9. log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository.

    The reason for the error is a new listener in Tomcat 6.0.24. You can fix this error by adding this l ...

  10. dedecms lnmp 环境搭建。备忘录非教程

    ssh链接到linux服务器,我用的centos 6.5 64位的. #设置dns,ect/reserv.conf 设置,注释掉原来的nameserver,添加nameserver=8.8.8.8访问 ...