Problem Description
There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number. Given an integer n(2 <= n <= 109).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
The first line contains integer T(1<= T<= 10000),denote the number of the test cases. For each test cases,the first line contains an integer n.
 
Output
For each test cases,print the maximum [a,b] in a line.
 
Sample Input
3 2 3 4
 
Sample Output
1 2 3
 
Author
WJMZBMR
 
Source
 

题意:给定一个数n,要求是找到一对数a、b,使得a+b=n,且a和b的最小公倍数要最大,求最大的最小公倍数。

思路:直接暴力查询,找出最大的值。具体看代码。时间复杂度是O(n),并不会超时。注意要用long long,会爆int。

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
using namespace std;
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1000000
#define inf 1e12
ll n;
ll gcd(ll a,ll b){
return b==?a:gcd(b,a%b);
}
ll lcm(ll a,ll b){
return a*b/gcd(a,b);
}
int main()
{
ll t;
scanf("%I64d",&t);
while(t--){
scanf("%I64d",&n); ll x=n/;
ll r=gcd(x,n-x);
ll ans=x*(n-x)/r;
while(r!= && x>){
x--;
r=gcd(x,n-x);
ans=max(ans,x*(n-x)/r);
}
printf("%I64d\n",ans);
}
return ;
}

hdu 4627 The Unsolvable Problem(暴力的搜索)的更多相关文章

  1. hdu 4627 The Unsolvable Problem【hdu2013多校3签到】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4627 The Unsolvable Problem Time Limit: 2000/1000 MS ( ...

  2. hdu 4627 The Unsolvable Problem

    http://acm.hdu.edu.cn/showproblem.php?pid=4627 分类讨论一下就可以 代码: #include<iostream> #include<cs ...

  3. HDU 4627 The Unsolvable Problem(简单题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 题目大意:给定一个整数n(2 <= n <= 109),满足a+b=n并且[a,b] ...

  4. HDU 4627 The Unsolvable Problem 2013 Multi-University Training Contest 3

    给你一个数 n ( 2 <= n <= 109 ),现在需要你找到一对数a, b (a + b = n),并且使得LCM(a, b)尽可能的大,然后输出最大的 LCM(a, b). (为什 ...

  5. HDU 4627 The Unsolvable Problem 杭电多校联赛第三场1009 数学题

    题意描述:给出一个n,要求在所有满足n = a+b的a和b里面求a和b的最小公倍数最大的两个数的最小公倍数. 解题报告:比赛的时候看到这个题的第一反应就是寻找这两个数一定是在a和b比较接近的地方找,这 ...

  6. hdu 1016 Prime Ring Problem(深度优先搜索)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. 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 ...

  8. HDU 4627(最小公倍数最大问题)

    HDU 4627 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descript ...

  9. HDOJ(HDU).1016 Prime Ring Problem (DFS)

    HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

随机推荐

  1. Implement Trie (Prefix Tree) 解答

    Question Implement a trie with insert, search, and startsWith methods. Note:You may assume that all ...

  2. java Socket 使用注意

    Socket s = new Socket(ia, port); BufferedOutputStream bufOut = new BufferedOutputStream(s.getOutputS ...

  3. 格而知之7:我所理解的Runtime(2)

    消息发送(Messaging) 8.以上便是runtime相关的一些数据结构,接下来我们回看一开始的疑问: objc_msgSend()函数在执行的过程中是如何找到对应的类,找到对应的方法实现的呢? ...

  4. Servlet页面间对象传递的方法

    Servlet页面间对象传递的方法 1.request 2.session 3.application 4.cookie 5.其它的

  5. java值传递

    Java使用按值传递的函数调用方式,这往往使我感到迷惑.因为在基础数据类型和对象的传递上,我就会纠结于到底是按值传递,还是按引用传递.其实经过学习,Java在任何地方,都一直发挥着按值传递的本色. 首 ...

  6. 多线程中的lua同步问题

    最近写paintsnow::start时出现了一个非常麻烦的BUG,程序的Release版本大约每运行十几次就会有一次启动时崩溃(Debug版本还没崩溃过),崩溃点也不固定.经过简单分析之后,确定是线 ...

  7. 【贪心】【uva11520】 Fill the Square

    填充正方形(Fill the Square, UVa 11520) 在一个n×n网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如 ...

  8. C# 多线程的坑 之 代码变序

    英文好的,可跳过,直接打开底部的“参考“链接. 代码变序--reordering of memory operations 大概4年前,阅读了这篇文章后http://www.albahari.com/ ...

  9. android——生成或者下载的图片在相册中找不到

    今天在写程序的时候,遇到了一个问题,就是生成的图片一直都不能在相册中显示出来,而且,就连通过发送Intent过去,都找不到.通过在网上搜索,发现了一个很好的方法. Intent intent = ne ...

  10. Remove Duplicate Letters

    316. Remove Duplicate Letters Total Accepted: 2367 Total Submissions: 12388 Difficulty: Medium Given ...