当前位置:网站首页>奇妙秘境 码蹄集
奇妙秘境 码蹄集
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;
}
边栏推荐
猜你喜欢
近日小结(非技术文)
字节面试算法题
392. 判断子序列
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)
ASP. Net core introduction I
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
安装trinity、解决报错
MySQL 5 installation and modification free
.Net之延迟队列
随机推荐
MySQL version 8 installation Free Tutorial
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
Read excel table data
苹果5G芯片研发失败:继续依赖高通,还要担心被起诉?
2022危险化学品经营单位主要负责人练习题及模拟考试
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
Go 语言入门很简单:Go 实现凯撒密码
一次 Keepalived 高可用的事故,让我重学了一遍它
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
Install Trinity and solve error reporting
Scripy framework learning
程序员转方向
Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present
One of the solutions for unity not recognizing riders
C language Dormitory Management Query Software
【C 题集】of Ⅶ
How to choose a technology stack for web applications in 2022
FS4059C是5V输入升压充电12.6V1.2A给三节锂电池充电芯片 输入小电流不会拉死,温度60°建议1000-1100MA
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)