当前位置:网站首页>奇妙秘境 码蹄集
奇妙秘境 码蹄集
2022-07-04 12:50:00 【Elvin域文】
题目:冒险团正在一座奇妙秘境探险,眼前正是秘境奖励关,关卡机制如下:随机给定M个金币,如果能找到三个不大于M的整数(可以相同), 求得它们的最小公倍数S,那么冒险团就可以获得S枚金币,为了得到最多的金币,大家一致决定将这项求解任务交给你这位团队智囊,求出S的最大值。
格式:
输入格式:输入一个正整数n
输出格式:输出题意中三个数的最小公倍数S的最大值
样例:
输入 :10 输出 :630
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n;
vector<long long int> arr;
vector<long long int> arr2;
long long int temp, c, d;
long long int min,min2;
bool flag;
cin >> n;
if(n > 2) {
arr.insert(arr.end(),n);
arr.insert(arr.end(), n-1);
arr.insert(arr.end(),n-2);
sort(arr.begin(), arr.end());
while(arr.size()>1){
c = arr[0];
d = arr[1];
min = c*d;
// cout << min << endl; 两个元素相同时
temp = c%d;
while(temp){
c = d;
d = temp;
temp = c%d;
}
min = min/d;
arr.erase(arr.begin(),arr.begin()+2);
arr.insert(arr.begin(),min);
}
if(n-3>0){
flag = 1;
arr2.insert(arr2.end(),n);
arr2.insert(arr2.end(), n-1);
arr2.insert(arr2.end(),n-3);
sort(arr2.begin(),arr2.end());
while(arr2.size()>1){
c = arr2[0];
d = arr2[1];
min2 = c*d;
temp = c%d;
// for(int i=0;i<arr2.size();i++){
// cout << arr2[i] << endl;
// }
while(temp){
c = d;
d = temp;
temp = c%d;
}
min2 = min2/d;
arr2.erase(arr2.begin(),arr2.begin()+2);
arr2.insert(arr2.begin(),min2);
}
}
if(flag){
if(min2 > min) {
min = min2;
}
}
}
else{
if(n==2){
min = 4;
}
else{
min =1;
}
}
cout << min;
return 0;
}
边栏推荐
- Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present
- OpenHarmony应用开发之如何创建DAYU200预览器
- .Net之延迟队列
- Gorm 读写分离(转)
- 国内酒店交易DDD应用与实践——代码篇
- The only core indicator of high-quality software architecture
- 逆向调试入门-PE结构-资源表07/07
- Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
- Install Trinity and solve error reporting
- 动画与过渡效果
猜你喜欢

分布式BASE理论

2022年山东省安全员C证考试题库及在线模拟考试

基于STM32+华为云IOT设计的酒驾监控系统

2022危险化学品经营单位主要负责人练习题及模拟考试

Unittest中的TestSuite和TestRunner

MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍

The only core indicator of high-quality software architecture

吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest

2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance

如何在 2022 年为 Web 应用程序选择技术堆栈
随机推荐
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
OPPO Find N2产品形态首曝:补齐各项短板
安装trinity、解决报错
C语言程序设计选题参考
Detailed explanation of Fisher information quantity detection countermeasure sample code
结合案例:Flink框架中的最底层API(ProcessFunction)用法
WS2818M是CPC8封装,是三通道LED驱动控制专用电路外置IC全彩双信号5V32灯可编程led灯带户外工程
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍
Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
基于YOLOv1的口罩佩戴检测
392. 判断子序列
2022年山东省安全员C证考试题库及在线模拟考试
JVM 内存布局详解,图文并茂,写得太好了!
Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
吃透Chisel语言.03.写给Verilog转Chisel的开发者(没有Verilog基础也可以看看)
JVM series - stack and heap, method area day1-2
#yyds干货盘点# 解决名企真题:连续最大和
IP 实验室月复盘 · 第 5 期
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)