Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
2016-02-13 16:49
344 查看
A. LCM Challenge
题目连接:
http://www.codeforces.com/contest/235/problem/ADescription
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
9Sample Output
504Hint
题意
从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; }
相关文章推荐
- OPNCV
- PHP session handler
- WERTYU
- apk 签名
- Vim升华之树形目录插件NERDTree安装图解
- centos7 安装后恢复windows启动
- Vim升华之树形目录插件NERDTree安装图解
- 如何成为一名卓越的前端工程师
- PHP 转编码函数
- 计算PI的方法
- 【HDU4416】Good Article Good sentence【后缀数组】
- php_imagick超强的PHP图片处理扩展
- php fread buffer问题
- [异常解决] android studio检测不到手机的解决办法——ADB驱动自己安装
- 从Settings数据库中取boolean类型数据
- 第11讲项目1——分离各位数
- php+uploadprogress实现上传进度功能
- Android TextView 设置字体大小的方法
- Android AutoLayout全新的适配方式 堪称适配终结者
- 习题10-1 11040 Add bricks in the wall 砌砖