[CF235A] LCM Challenge - 贪心
找到3个不超过n的正整数(可以相同),使得它们的lcm(最小公倍数)最大。
Solution
可以做得很优雅吧,但我喜欢(只会)暴力一点
根据质数密度分布性质,最后所取的这三个数一定不会比 \(n\) 小太多(实在不行就取三个质数呀),所以我们钦定一个界,然后暴力枚举取最优即可
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
signed main() {
cin>>n;
int ans=0;
for(int i=max(1ll,n-80);i<=n;i++) {
for(int j=max(1ll,n-80);j<=n;j++) {
for(int k=max(1ll,n-80);k<=n;k++) {
int g=i*j/__gcd(i,j);
int u=g*k/__gcd(g,k);
ans=max(ans,u);
}
}
}
cout<<ans;
}
[CF235A] LCM Challenge - 贪心的更多相关文章
- acdream.LCM Challenge(数学推导)
LCM Challenge Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Submit ...
- [codeforces 235]A. LCM Challenge
[codeforces 235]A. LCM Challenge 试题描述 Some days ago, I learned the concept of LCM (least common mult ...
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
- acdream LCM Challenge (最小公倍数)
LCM Challenge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Su ...
- A - LCM Challenge
A - LCM Challenge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others ...
- CF235A 【LCM Challenge】
这题好毒瘤啊 (特别是long long的坑,调了半天没调好!!)先将你特判一下小于3的话直接输出就是惹,不是的话就判断一下它能不能被2整除如果不能就直接输出n*(n-1)*(n-2)否则进行枚举枚举 ...
- acd LCM Challenge(求1~n的随意三个数的最大公倍数)
Problem Description Some days ago, I learned the concept of LCM (least common multiple). I've played ...
- Codeforces B. Minimum Possible LCM(贪心数论)
题目描述: B. Minimum Possible LCM time limit per test 4 seconds memory limit per test 1024 megabytes inp ...
- Codeforces Round #146 (Div. 2)
A. Boy or Girl 模拟题意. B. Easy Number Challenge 筛素数,预处理出\(d_i\). 三重循环枚举. C. LCM Challenge 打表找规律. 若\(n\ ...
随机推荐
- Elasticsearch之集群
ElasticSearch集群 ES集群是一个 P2P类型(使用 gossip 协议)的分布式系统,除了集群状态管理以外,其他所有的请求都可以发送到集群内任意一台节点上,这个节点可以自己找到需要转发给 ...
- C#中实现文件拖放打开的方法
C#中实现文件拖放打开的方法 设置Form属性 AllowDrop = True; 在Form事件中 private void Form1_DragDrop(object sender, DragEv ...
- [WPF 自定义控件]创建包含CheckBox的ListBoxItem
1. 前言 Xceed wpftoolkit提供了一个CheckListBox,效果如下: 不过它用起来不怎么样,与其这样还不如参考UWP的ListView实现,而且动画效果也很好看: 它的样式如下: ...
- JavaScript-状态模式
状态模式 一个对象有状态变化 每次状态变化都会触发一个逻辑 不能总是用 if...else 来控制 示例:交通信号灯的不同颜色变化 传统的 UML 类图 javascript 中的 UML 类图 cl ...
- 带输入提示的搜索框ajax请求
先放图 首先要引用的文件有: base.css https://www.cnblogs.com/chenyingying0/p/12363689.html jquery.js transition. ...
- 方法中this指向的问题
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Linux_simpl shell-利用Shell脚本for循环输出系统中的用户及其Shell
[root@localhost ~]# vim user.sh 1 #!/bin/bash 2 for i in `cut -d ":" -f1 /etc/passwd`; 3 d ...
- docker安装mysql/redis
1.安装mysql容器 #搜索mysql镜像 docker search mysql #拉取mysql镜像 docker pull docker.io/mysql #创建mysql容器,MYSQL_R ...
- Linux nohup不输出日志文件的方法
引用:https://blog.csdn.net/guotao15285007494/article/details/84136234 最近在Linux上部署视频流推送应用时,由于网络不稳定等原因程序 ...
- 实验一Git代码版本管理
GIT代码版本管理 实验目的: 1)了解分布式分布式版本控制系统的核心机理: 2) 熟练掌握git的基本指令和分支管理指令: 实验内容: 1)安装git 2)初始配置git ,git init git ...