ACdream1077-LCM Challenge
来源:互联网 发布:ubuntu rc.local不存在 编辑:程序博客网 时间:2024/05/22 00:20
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
Source
Manager
题意:求不超过n的三个数的最大公倍数。
解题思路:首先要知道两个数论性质:1、相邻两个整数互质2、相邻两个奇数互质
然后,小数据观察规律,按n的奇偶性讨论。
一、n为奇数时,n-2必定为奇数,而n-1与它俩都相邻,因此,两两互质。最大公倍数即为n*(n-1)*(n-2)
二、n为偶数时,由于n与n-2均为偶数,所以,退而求其次,选择n-3。又n与n-3是否互质,衍生出两种情况:
1、n为3的倍数,则n与n-3不互质,然而,n与n-4不互质,所以,此时,不选择n,改为选n-2。最后最大公倍数即为(n-1)*(n-2)*(n-3)
2、n不为3的倍数,则n与n-3互质,最后最大公倍数即为 n*(n-1)*(n-3)
#include <stdio.h>#include <math.h>#include <string.h>#include <algorithm>using namespace std;#define ll long longint main(){ ll n; while(~scanf("%lld",&n)) { if(n==1) printf("1\n"); else if(n==2) printf("2\n"); else if(n%2!=0) printf("%lld\n",n*(n-1)*(n-2)); else if(n%3==0) printf("%lld\n",(n-1)*(n-2)*(n-3)); else printf("%lld\n", n*(n-1)*(n-3)); } return 0;}
- ACdream1077:LCM Challenge
- ACdream1077 LCM Challenge 数学题
- ACdream1077-LCM Challenge
- LCM Challenge
- LCM Challenge(最小公倍数)
- LCM Challenge(数论)
- LCM Challenge(暴力)
- LCM Challenge--codeForces 235A
- cf146div2_c. LCM Challenge
- CodeForces 235A LCM Challenge
- ACdream 1077 LCM Challenge (数学题)(LCM)
- Codeforces Round #146 (Div. 2) C. LCM Challenge
- Codeforces Round #146 (Div. 2) C. LCM Challenge
- Codeforces 236C LCM Challenge 数论(基础题)
- Codeforces Round #146 (Div. 2)-C. LCM Challenge
- acd LCM Challenge(求1~n的任意三个数的最大公倍数)
- Codeforces Round #146 (Div. 1) LCM Challenge 解题报告 数论 找规律
- lcm
- 第十期 路由器调试之HelloWorld 《路由器就是开发板》
- google亚太在线笔试2017-RoundB
- 这是我的第一篇csdn博客,仅作测试使用
- 微信开发一笔记
- SharedPreferences
- ACdream1077-LCM Challenge
- VB.net组合框笔记
- Android Studio配置,加快编译速度
- php定时执行、取消定时的伪代码(低级版本)
- 迭代器的小用法
- Material Design
- 发送图片到服务器
- 深度剖析ConcurrentHashMap
- 性能测试知多少--系统计数器与硬件分析