当前位置:网站首页>奇妙秘境 码蹄集
奇妙秘境 码蹄集
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;
}
边栏推荐
- E-week finance | Q1 the number of active people in the insurance industry was 86.8867 million, and the licenses of 19 Payment institutions were cancelled
- Summary of recent days (non-technical article)
- 2022g3 boiler water treatment examination question simulation examination question bank and simulation examination
- FS4059C是5V输入升压充电12.6V1.2A给三节锂电池充电芯片 输入小电流不会拉死,温度60°建议1000-1100MA
- FS7867S是一款应用于数字系统供电电源电压监控的电压检测芯片
- C language dormitory management query software
- 基于YOLOv1的口罩佩戴检测
- 【R语言数据科学】:交叉验证再回首
- 硬件基础知识-二极管基础
- IDEA快捷键大全
猜你喜欢
如何在 2022 年为 Web 应用程序选择技术堆栈
分布式BASE理论
MySQL 45 lecture - learn the actual combat notes of MySQL in Geek time 45 lecture - 06 | global lock and table lock_ Why are there so many obstacles in adding a field to the table
【R语言数据科学】:交叉验证再回首
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
基于STM32+华为云IOT设计的酒驾监控系统
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
2022危险化学品经营单位主要负责人练习题及模拟考试
字节面试算法题
随机推荐
unity不识别rider的其中一种解决方法
2022G3锅炉水处理考试题模拟考试题库及模拟考试
Unittest中的TestSuite和TestRunner
Byte interview algorithm question
Animation and transition effects
一次 Keepalived 高可用的事故,让我重学了一遍它
2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance
C语言宿舍管理查询软件
C language programming topic reference
程序员的焦虑
Huahao Zhongtian sprint Technology Innovation Board: perte annuelle de 280 millions de RMB, projet de collecte de fonds de 1,5 milliard de Beida Pharmaceutical est actionnaire
JVM series - stack and heap, method area day1-2
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
WS2811 M是三通道LED驱动控制专用电路彩灯带方案开发
DGraph: 大规模动态图数据集
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
以房抵债能否排除强制执行
Openharmony application development how to create dayu200 previewer