A - LCM Challenge
A - 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,让你从1~n中找出三个数,使他们的最大公倍数最大。(补充下小学五年级的知识:两个相临的奇数互质)
我们知道要是他们的最大公倍数最大,既为从最大的n,n-1,n-2开始查找,
而且如果n为奇数的话,n*(n-1)*(n-2)=>奇数*偶数*奇数(且三个数互质),一定是所求最大的公倍数。
如果n为偶数的话,则有两种情况:
1,n能够被3整除;
1,n不能够被3整除;
因为n是偶数n*(n-1)*(n-2)=>偶数*奇数*偶数(且三个数不互质)<>不会是最大公倍数, 所以它的最大公倍数顶多为n*(n-1)*(n-3)=>偶数*奇数*奇数(此时三个数可能不互质),
这里还需要判断的是n是否能够被3整除。
为什么只考虑只能被3整除的情况呢?
因为只有三个数,如果n能够被3整除的话,如果n能够被3整除的话,这三个数也便不互质了、
它的最大公倍数不可能是为n*(n-1)*(n-3),因为n-3同样也能够被3整除,
这么三个数也不互质,最大值顶多可能是n*(n-1)*(n-5)=>偶数*奇数*奇数(不一定互质)以及更小,
或者为(n-1)*(n-2)*(n-3)=>奇数*偶数*奇数(且三个数互质),
因为(n-1)*(n-2)*(n-3)-n*(n-1)*(n-5)
=>(n-1)*{(n-2)*(n-3)-(n)*(n-5)}
=>(n-1)*{(n*n-5*n)+6-(n*n-5*n)}
=>(n-1)*6
因为n>=1所以(n-1)*(n-2)*(n-3)>n*(n-1)(n-5)
所以,当n为偶数,且能够被3整除的话,输出(n-1)*(n-2)*(n-3)
否则输出(n)*(n-1)*(n-3)
#include <stdio.h>
int main()
{
long long n;
while(scanf("%lld",&n)!=EOF)
{
if(n==)printf("1\n");
else if(n==)printf("2\n");
else if(n%==)/*奇数*/
{
printf("%lld\n",n*(n-)*(n-));
}
else if(n%==)/*能被6整除*/
{
printf("%lld\n",(n-)*(n-)*(n-));
}
else /*能被2整除*/
{
printf("%lld\n",(n)*(n-)*(n-));
}
}
return ;
}
A - 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 ...
 - acdream  LCM Challenge (最小公倍数)
		
LCM Challenge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Su ...
 - acd LCM Challenge(求1~n的随意三个数的最大公倍数)
		
Problem Description Some days ago, I learned the concept of LCM (least common multiple). I've played ...
 - [CF235A] LCM Challenge - 贪心
		
找到3个不超过n的正整数(可以相同),使得它们的lcm(最小公倍数)最大. Solution 可以做得很优雅吧,但我喜欢(只会)暴力一点 根据质数密度分布性质,最后所取的这三个数一定不会比 \(n\) ...
 - CF235A 【LCM Challenge】
		
这题好毒瘤啊 (特别是long long的坑,调了半天没调好!!)先将你特判一下小于3的话直接输出就是惹,不是的话就判断一下它能不能被2整除如果不能就直接输出n*(n-1)*(n-2)否则进行枚举枚举 ...
 - Codeforces Round #146 (Div. 2)
		
A. Boy or Girl 模拟题意. B. Easy Number Challenge 筛素数,预处理出\(d_i\). 三重循环枚举. C. LCM Challenge 打表找规律. 若\(n\ ...
 - ACdream区域赛指导赛之手速赛系列(2)
		
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/DaiHaoC83E15/article/details/26187183 回到作案现场 ...
 
随机推荐
- PHP5.5在windows 安装使用 memcached 服务端的方法以及 php_memcache.dll 下载
			
PHP5.5 在windows下安装 memcached 的方法 下载服务端资源 http://download.csdn.net/detail/zsjangel/7104727 下载完成后,解压(我 ...
 - Hadoop优先级调度
			
当同时在集群中运行多个作业时,默认情况下,Hadoop将提交的作业放入一个FIFO,一个作业结束后,Hadoop就启动下一个作业. 当一个运行时间长但是优先级较低的作业先于运行时间短而优先级较高的作业 ...
 - C#Winform实现自动更新
			
服务端: [WebMethod] public string GetNewService(string version) { //通过版本号进行比较 if (version == "v1.0 ...
 - AC自动机(AC automation)
			
字典树+KMP 参考自: http://www.cppblog.com/mythit/archive/2009/04/21/80633.html ; //字典大小 //定义结点 struct node ...
 - Redis Cluster 实践
			
一:关于redis cluster 1:redis cluster的现状 reids-cluster计划在redis3.0中推出,可以看作者antirez的声明:http://antirez.com/ ...
 - mysql5.5修改字符编码
			
因为mysql版本问题,网上各种修改编码的方法都不行,最后找到下面这条,终于解决! [mysqld]下添加: character-set-server=utf8 collation-server=ut ...
 - JMeter+ant+jenkins自动化持续集成
			
一.ant安装配置 1.官网下载地址:http://ant.apache.org/bindownload.cgi 对应的操作系统选择对应的版本下载,本文以windows为列,下载后解压到本地 2.设置 ...
 - MapReduce库类
			
Hadoop除了可以让开发人员自行编写map函数和reduce函数,还提供一些常用函数(mapper.reducer和partitioner)的类库,这些类位于 org.apache.hadoop.m ...
 - ajax请求相关方法
			
jquery的ajax请求相关方法有多个: 1.$.ajax() 示例: <!DOCTYPE html> <html> <head> <meta charse ...
 - jquery选择器之基本筛选选择
			
1.基本选择器 2.内容筛选选择器 3.可见性筛选选择器 4.属性筛选选择器 5.子元素筛选选择器 6.表单元素选择器 7.表单对象属性筛选器