acdream LCM Challenge (最小公倍数)
LCM Challenge
Problem 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
Output
Sample Input
9
Sample Output
504
题意:给一个数n,要求找3个小于等于n的数,3个数的最小公倍数LCM(a1,a2,a3)最大。
分析:其实就是要找3个两两互质的数,但是只是如何找的问题。
根据连续的两个奇数互质,连续的两个自然数互质。那么答案很明显了,3个最大的互质的数的最小公倍数肯定最大。
如果n是奇数,那么答案是n*(n-1)*(n-2)。
如果n是偶数就麻烦了点,要么是如果n和n-2互质,那么答案就是n*(n-1)*(n-2),因为他们是最大的3个互质的数。但是如果是n和n-2不互质,那么答案是(n-3)*(n-1)*(n-2),因为n-1之后肯定是奇数了,用奇数的方法。
/*
* this code is made by xcw0754
* Problem: 1077
* Verdict: Accepted
* Submission Date: 2015-07-16 10:24:02
* Time: 0MS
* Memory: 1672KB
*/
#include <bits/stdc++.h>
#define LL long long
#define pii pair<int,int>
#define INF 0x7f7f7f7f
using namespace std;
const int N=+; LL cal(LL n) //偶数
{
LL ans=;
//n n-1 n-3
if(__gcd(n,n-)==) ans=max(ans, n*(n-)*(n-)); //n-1 n-2 n-3
ans=max(ans, (n-)*(n-)*(n-)); return ans;
} int main()
{
//freopen("input.txt", "r", stdin);
LL n;
scanf("%lld",&n);
if(n==) printf("1\n");
else if(n==) printf("2\n");
else if(n==) printf("6\n");
else if(n==) printf("12\n");
else if(n==) printf("60\n");
else
{
if((n&)==) cout<<cal(n)<<endl;
else cout<<n*(n-)*(n-)<<endl;
}
return ;
}
AC代码
acdream LCM Challenge (最小公倍数)的更多相关文章
- acdream.LCM Challenge(数学推导)
LCM Challenge Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Submit ...
- [codeforces 235]A. LCM Challenge
[codeforces 235]A. LCM Challenge 试题描述 Some days ago, I learned the concept of LCM (least common mult ...
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
- A - LCM Challenge
A - LCM Challenge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others ...
- 求gcd(最大公因数),lcm(最小公倍数)模板
gcd(最大公因数),lcm(最小公倍数) #include<iostream> using namespace std; int gcd(int a,int b)//辗转相除法(欧几里德 ...
- [CF235A] LCM Challenge - 贪心
找到3个不超过n的正整数(可以相同),使得它们的lcm(最小公倍数)最大. Solution 可以做得很优雅吧,但我喜欢(只会)暴力一点 根据质数密度分布性质,最后所取的这三个数一定不会比 \(n\) ...
- acd LCM Challenge(求1~n的随意三个数的最大公倍数)
Problem Description Some days ago, I learned the concept of LCM (least common multiple). I've played ...
- GCD(最大公约数)和LCM(最小公倍数)的求法
GCD(最大公约数) (1)辗转相除法(欧几里得算法)(常用) 将两个数a, b相除,如果余数c不等于0,就把b的值给a,c的值给b,直到c等于0,此时最大公约数就是b (2)更相减损术 将两个书中较 ...
- BNU 12846 LCM Extreme 最小公倍数之和(线性欧拉筛选+递推)
LCM Extreme Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Orig ...
随机推荐
- PySide 简易教程<一>-------Hello PySide
PySide 是一个python绑定的跨平台GUI Qt库.目前,支持Python的Qt库有两个PyQt和PySide.PySide是一个免费的软件,与PyQt不同之处在于使用了LGPL,允许PySi ...
- Elasticsearch升级至1.x后API的变化-三
请支持原创:http://www.cnblogs.com/donlianli/p/3841762.html 1.索引格式 1.x之前的版本,被索引的文档type会同时出现在url和传输的数据格式中 ...
- vs2008+cmake2.8+OpenCV2.8.4配置过程中OpenCV.sln重编译部分工程失败
解决方法来自此链接 http://www.tuicool.com/articles/qiQBb2N vs2008+cmake2.8+OpenCV2.8.4配置过程 1.解压opencv2.4.8 2. ...
- storyboard 总结
1.storyboard 布局时用代码实现页面跳转: a> 获取当前 storyboard : [self storyboard] b> 为将要跳转到的 viewController 添加 ...
- JavaBean 和 Map 之间互相转换
JavaBean 和 Map 之间互相转换 import java.beans.BeanInfo; import java.beans.IntrospectionException; import j ...
- 4.3 spring-嵌入式beans标签的解析
对于嵌入式的beans标签,想信大家很少使用过,或者接触过,起码,我本人就没用过. 它非常类似于Import标签所提供的功能; 使用如下: <?xml version="1.0&quo ...
- css3实现非矩形图片效果
经常在网站上看到有一些非矩形的图片展示.在以前可能我会毫不犹豫的直接放上张处理好的图片.但是这样的话确实有些不太友好.每每需要换图的时候,都要去开图像处理软件也是蛮拼的.自从有了css3的选装,妈妈就 ...
- Recommender Systems引言
我想站在大神肩膀上...貌似是计算所的一个小伙伴... 总结的很好,看得出来有一定的功底.... 不过对于自己看过了的东西,就不愿意再翻看第二遍了.恰好这本书和项亮那本很像,就直接看这本书了.顺便记记 ...
- Hex string convert to integer with stringstream
#include <sstream>#include <iostream>int main() { unsigned int x; std::stringstream ss; ...
- Tornado,表单处理,一样在行
哟,处理流程还算自然... import os.path import random import tornado.httpserver import tornado.ioloop import to ...