您的位置:首页 > 其它

HDU 4627 The Unsolvable Problem

2014-08-30 11:24 381 查看

The Unsolvable Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1473    Accepted Submission(s): 717

[align=left]Problem Description[/align]
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.
 

[align=left]Input[/align]
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.
 

[align=left]Output[/align]
For each test cases,print the maximum [a,b] in a line.
 

[align=left]Sample Input[/align]

3
2
3
4

 

[align=left]Sample Output[/align]

1
2
3

 

[align=left]Source[/align]
2013 Multi-University Training Contest


题目大意:
         给你一个n,让你求a+b=n时,a,b的最小公倍数的值最大.

题解:
       

当两个数互质的时候,它们的最小公倍数就是它们的乘积,并且当a+b=n,时,当|a-b|的绝对值越小时,它们的乘积越大。
#include<stdio.h>
int gcd(int a,int b)  //求最大公约数
{
return b?gcd(b,a%b):a;
}
int main()
{
int n,N,m,i;
scanf("%d",&N);
while(N--)
{
scanf("%d",&n);
m=n/2;
for(i=m;;i--)
{
if(gcd(i,n-i)==1)
break;
}
printf("%I64d\n",(long long )i*(n-i));//注意化为长整型输出
}
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HDU 数论 4627