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. codecomb 2098【stone】

    题目描述 Description n个石堆围成一圈,提供两种操作: 1.每次将[L,R]堆的石子数量+k,其中,1<=L,R<=n,k>=0. 2.询问有最多石子的那一堆有多少石子. ...

  2. knowledges address

    http://www.zhukun.net/archives/5794

  3. PHP 文件打开/读取

    PHP Open File - fopen() 打开文件的更好的方法是通过 fopen() 函数.此函数为您提供比 readfile() 函数更多的选项. 在课程中,我们将使用文本文件 "w ...

  4. $.cookie is not a function

    在调试网站的时候,用jquery获取cookie时,报错: $.cookie is not a function; 一般情况$.cookie is not a function;错误原因: 一.没有引 ...

  5. 如何把UIView转成UIImage,解决模糊失真问题

    最近工作中,遇到一个需求,需要把一个UIView对象转成UIImage对象显示.经过网络搜索,找到如下答案: ? 1 2 3 4 5 6 7 8 -(UIImage*)convertViewToIma ...

  6. 【模拟】【HDU1443】 Joseph

    Joseph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  7. 获取系统的IP

    如何获取Linux系统的ip.当时一直用这种方法获取IP的. ifconfig|grep 'Bcast'|awk -F ':' '{print $2}'|awk '{print $1}' 今天偶然发现 ...

  8. session之退出登陆

    <span style="font-size:32px;">//使用SESSION必须先开启session session_start(); //彻底删除session ...

  9. nodejs中的 Cannot read property'text' of undefined 问题

    接触nodejs时间不久,最近遇到了这个问题,经过查阅资料以及百度终于解决了.

  10. php zendstudio 常用的一些自定义模板标签

    <?php /** * xxx.php * ============================================== * Copy right 2013-2016 http: ...