HDU 4627(最小公倍数最大问题)
HDU 4627
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Given an integer n(2 <= n <= 10 9).We should find a pair of positive integer a, b so that a + b = n and [a, b] is as large as possible. [a, b] denote the least common multiplier of a, b.
Input
For each test cases,the first line contains an integer n.
Output
Sample Input
2
3
4
Sample Output
2
3
#include <stdio.h>
int main()
{
int a,b,c;
int max,min,t1,t2;
int i,n,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
max=;
for(i=; i<=n/; i++)
{
a=i;
b=n-i;
a>b?t1=a:t1=b;
t2=n-t1;
while(t2)
{
c=t1%t2;
t1=t2;
t2=c;
}
min=a*b/t1;
if(min>max)
max=min;
}
printf("%d\n",max);
}
return ;
}
另外还有一种,这是一种奇偶求法,很简单巧妙,经某ACM大神指点得知
#include <stdio.h> int main()
{
int n,T;
long long max;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
max=;
if (n==) printf("1\n");
else
{
if (n%==)
{
max=n/;
if (max%==) max=(max+)*(max-);
else max=(max+)*(max-);
}
else
{
max=n/;
max=max*(max+);
}
printf("%I64d\n",max);
}
}
return ;
}
HDU 4627(最小公倍数最大问题)的更多相关文章
- HDU 4627 The Unsolvable Problem(简单题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 题目大意:给定一个整数n(2 <= n <= 109),满足a+b=n并且[a,b] ...
- 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 1713 最小公倍数与最大公约数的问题 相遇周期
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) 相遇周期 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/ ...
- hdu 4627 The Unsolvable Problem
http://acm.hdu.edu.cn/showproblem.php?pid=4627 分类讨论一下就可以 代码: #include<iostream> #include<cs ...
- 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 水数学题
最小公倍数最大,也就是尽量让2个数互质,所以把n除以2 从中间向两边找就够了,自己写几组数据就能发现规律. 注意longlong存 #include<cstdio> #include< ...
- hdu 4627 The Unsolvable Problem(暴力的搜索)
Problem Description There are many unsolvable problem in the world.It could be about one or about ze ...
- HDU 4627 The Unsolvable Problem 杭电多校联赛第三场1009 数学题
题意描述:给出一个n,要求在所有满足n = a+b的a和b里面求a和b的最小公倍数最大的两个数的最小公倍数. 解题报告:比赛的时候看到这个题的第一反应就是寻找这两个数一定是在a和b比较接近的地方找,这 ...
- hdu 1788 最小公倍数(这题面。。。)
Chinese remainder theorem again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
随机推荐
- Reward(拓扑排序)
http://acm.hdu.edu.cn/showproblem.php?pid=2647 题意: 老板要给n个员工发工资最低工资是888: 但是工人们是有要求的 如果输入 a b 表示a的工资要比 ...
- [Hibernate] List 映射例子
List 是 java 集合的一个工具,存储线性的数据,允许重复数据.开发者可以准确控制在 list 那个位置插入数据.本例子演示 Java 的 List 集合和 MySQL 数据库的映射应用. 使用 ...
- ubuntu编译openwrt前端web界面
openwrt是由Cisco放出源代码的开放无线路由平台.由于是基于linux内核,所以可以将很多linux平台下的软件移植到此平台下,然后让无线路由拥有很多意想不到的功能,例如拿来做BT下载器,音乐 ...
- RCMTM _百度百科
RCMTM _百度百科 RCMTM
- Moderate 加入空格使得可辨别单词数量最多 @CareerCup
递归题目,注意结合了memo的方法和trie的应用 package Moderate; import java.util.Hashtable; import CtCILibrary.AssortedM ...
- OpenGL ES2.0基础入门
1.OpenGL ES 1.x渲染管线(又称为渲染流水线) (1).基本处理: 基本处理主要是设定3D空间中物体的顶点坐标.顶点对应的颜色.顶点的纹理坐标等属性,并且指定绘制方式. 常见的绘制方式有: ...
- cocos2d_android开发简单游戏
1)游戏图层设计: public class WellcomeLayer extends CCLayer { public WellcomeLayer() { this.setIsTouchEnabl ...
- 浙江大学PAT上机题解析之1015. 德才论 (25)
宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人 ...
- ie11只能用管理员身份打开解决办法
解决IE11只能用管理员身份运行的问题 不知道大家有没有遇到这种情况,在毫不知情的情况下 IE11 突然打不开了,必须要用管理员身份运行才可以打开,而且重置浏览器这个方法也不奏效. 今天本人也遇到了, ...
- 《Android开发艺术探索》读书笔记 (3) 第3章 View的事件体系
本节和<Android群英传>中的第五章Scroll分析有关系,建议先阅读该章的总结 第3章 View的事件体系 3.1 View基本知识 (1)view的层次结构:ViewGroup也是 ...