当前位置:网站首页>奇妙秘境 码蹄集
奇妙秘境 码蹄集
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;
}
边栏推荐
- 逆向调试入门-PE结构-资源表07/07
- Unittest中的TestSuite和TestRunner
- 【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
- Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
- 2022g3 boiler water treatment examination question simulation examination question bank and simulation examination
- The Secretary of Homeland Security warned immigrants "not to embark on a dangerous journey"
- 国内酒店交易DDD应用与实践——代码篇
- 吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
- Introduction to XML I
- Byte interview algorithm question
猜你喜欢

德明利深交所上市:市值31亿 为李虎与田华夫妻档

OPPO Find N2产品形态首曝:补齐各项短板

Summary of recent days (non-technical article)

Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)

unity不识别rider的其中一种解决方法

MySQL8版本免安装步骤教程

中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东

2022 Shandong Province safety officer C certificate examination question bank and online simulation examination

近日小结(非技术文)

基于链表管理的单片机轮询程序框架
随机推荐
中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
205. 同构字符串
近日小结(非技术文)
BLOB,TEXT GEOMETRY or JSON column 'xxx' can't have a default value query 问题
sharding key type not supported
Animation and transition effects
remount of the / superblock failed: Permission denied
Go 语言入门很简单:Go 实现凯撒密码
markdown 语法之字体标红
吃透Chisel语言.04.Chisel基础(一)——信号类型和常量
Openharmony application development how to create dayu200 previewer
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
嵌入式编程中五个必探的“潜在错误”
Scripy framework learning
IP 实验室月复盘 · 第 5 期
mac redis安装与使用,连接远程服务器 redis
. Net using redis
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
吃透Chisel语言.03.写给Verilog转Chisel的开发者(没有Verilog基础也可以看看)
吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest