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 ...
随机推荐
- NOI题库1159 Maze
1159:Maze 总时间限制: 2000ms 内存限制: 65536kB 描述 Acm, a treasure-explorer, is exploring again. This time he ...
- 专注于个人服装定做_服装设计_Fabric_Design_Tailor-迦勒定制网
专注于个人服装定做_服装设计_Fabric_Design_Tailor-迦勒定制网 客服热线:400-720-7206 工作时间:AM 09:00-PM 10:00 周六/周日/节假日:设计师休息
- python面向对象【进阶篇】
静态方法 通过@staticmethod装饰器即可把其装饰的方法变为一个静态方法,什么是静态方法呢?其实不难理解,普通的方法,可以在实例化后直接调用,并且在方法里可以通过self.调用实例变量或类变量 ...
- slidingmenu+fragment实现经常使用的側滑效果(包含Fragment状态的保存)
一.需求 关于fragment的问题,一直想写一篇博客了.应该当初自己也是对这玩意一点都不熟悉到如今也大概知道个日常的使用的地步. 一个側滑的导航栏,内有4个条目.每个选项点击进入相应的界面,每个界面 ...
- 怎样使用 iOS 7 的 AVSpeechSynthesizer 制作有声书(2)
切分语句 软件project的一条定律是数据和代码分离.这样做会使代码更易于測试,即使输入的数据发生改变,你的代码也能够同意.甚至于,程序能在执行中实时下载新的数据.假设程序能在执行中下载新书岂不是更 ...
- TCP/IP之分层
网络协议通常分不同层次进行开发,每一层分别负责不同的通信功能.一个协议族,比方T C P / I P,是一组不同层次上的多个协议的组合.T C P / I P通常被觉得是一个四层协议系统. 1.每层的 ...
- U盘启动安装CentOS 6.3
无光驱U盘启动安装CentOS 6.3的一些必要条件: 1.主板要支持U盘启动 2.8G的U盘 3.UltraISO软件 http://www.linuxidc.com/Linux/2010-03/2 ...
- 图片预览(base64和blob:图片链接)和ajax上传、下载(带进度提示)
直接上代码 html和js <!DOCTYPE html> <html> <head> <meta name="viewport" con ...
- AsyncTask 解析
[转载自 http://blog.csdn.net/yanbober ] 1 背景 Android异步处理机制一直都是Android的一个核心,也是应用工程师面试的一个知识点.前面我们分析了Handl ...
- Linux基础系列—Linux内核源码目录结构
/** ****************************************************************************** * @author 暴走的小 ...