[hdu4627 The Unsolvable Problem]数论
题意:给一个数n,找一个正整数x<n,使得x和n-x的最小公倍数最大。
思路:显然x和n-x越接近越好,gcd必须为1(贪心)。从大到小考虑x,如果n为奇数,则答案就是x=n/2,如果n为偶数,令n=2k,如果k为奇数,且大于1则x=k-2否则x=k,如果k为偶数则x=k-1。以上结论基于以下两个事实:
(1)相邻两个数的gcd为1
(2)相邻两个奇数的gcd为1
(3)1和1的gcd为1
写的时候没用到这些事实,直接从n/2向下枚举,当gcd为1时得到答案
1 |
#include <map> |
[hdu4627 The Unsolvable Problem]数论的更多相关文章
- HDU-4627 The Unsolvable Problem 简单数学
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 对n除个2,然后考虑下奇偶... //STATUS:C++_AC_15MS_228KB #inc ...
- The Unsolvable Problem
The Unsolvable Problem 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=45783 题意: ...
- hdu 4627 The Unsolvable Problem(暴力的搜索)
Problem Description There are many unsolvable problem in the world.It could be about one or about ze ...
- 2013多校联合3 G The Unsolvable Problem(hdu 4627)
2013-07-30 20:35 388人阅读 评论(0) 收藏 举报 http://acm.hdu.edu.cn/showproblem.php?pid=4627 The Unsolvable Pr ...
- hdu 4627 The Unsolvable Problem【hdu2013多校3签到】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4627 The Unsolvable Problem Time Limit: 2000/1000 MS ( ...
- HDU 4627 There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number.
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82974#problem/E 解题思路:数论,从一个数的中间开始往两边找,找到两 ...
- UVA 11490 - Just Another Problem(数论)
11490 - Just Another Problem option=com_onlinejudge&Itemid=8&page=show_problem&category= ...
- HDU 5974 A Simple Math Problem(数论+结论)
Problem Description Given two positive integers a and b,find suitable X and Y to meet the conditions ...
- codeforces 633B B. A Trivial Problem(数论)
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- MRCTF Ezpop_Revenge小记
前言 一道typecho1.2的反序列化,顺便记录一下踩的坑 www.zip获得源码,结构大致如下 flag.php需要ssrf,如果成功会写入session 拿到源码直接去网上先找了一下有没有现成的 ...
- 乱 七 八 糟 $(n.)$
\(2020/4/22\) 今天常规作业还是太慢了,白天似乎已经抓紧了,但总还能挤出时间来的.八点钟了还有物理和英语作业,回去又得很晚睡. 还是容易开小差,不过回忆了一下,今天化学课还是太懒散,其余的 ...
- SpringBoot系列(十)优雅的处理统一异常处理与统一结果返回
SpringBoot系列(十)统一异常处理与统一结果返回 往期推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列 ...
- 2019-2020-1 20199325《Linux内核原理与分析》第二周作业
冯诺依曼计算机硬件框图: 下面是一个简单的程序example.c. intadd_a_and_b(int a,int b){returna+b;}intmain(){returnadd_a_and_b ...
- Zabbix3.0安装部署最佳实践
Zabbix介绍 1.1zabbix 简介 Zabbix 是一个高度集成的网络监控解决方案,可以提供企业级的开源分布式监控解决方案,由一个国外的团队持续维护更新,软件可以自由下载使用,运作团队靠提供收 ...
- NPM 私有仓库的搭建
NPM 私有仓库的搭建 为什么搭建私有仓库 balabala,当然是有需求的时候嘛 搭建流程 介绍和安装verdaccio 备注: 程序启动后,配置文件为/home/work/.config/verd ...
- UVA10599:Robots(II)(最长上升子序列)
Your company provides robots that can be used to pick up litter from fields after sporting events an ...
- Redis(二):单机数据库的实现
概要 本部分内容主要是研究单机数据库.分别介绍单机数据库的实现原理,数据库的持久化,Redis事件,服务器维护管理客户端以及单机服务器的运作机制. 数据库 数据库结构 Redis数据库由redis.h ...
- Android环境配置----在Ubuntu上安装JDK
jdk download address: jdk-6u22-linux-i586.bin http://www.oracle.com/technetwor ... ownloads/index.ht ...
- 实战经验:CentOS 7.3安装完整开发环境
系统版本 CentOS 7.3(1611) 安装开发环境 1) 通过group安装 # yum groups mark install “Development Tools” # yum groups ...