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
3
题目大意:
给你一个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 The Unsolvable Problem
- hdu - 4627 - The Unsolvable Problem
- hdu 4627 The Unsolvable Problem (数论)
- 2013多校联合3 G The Unsolvable Problem(hdu 4627)
- hdu 4627 The Unsolvable Problem
- hdu 4627 The Unsolvable Problem
- HDU 4627 There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number.
- HDU 4627 The Unsolvable Problem(简单题)
- hdu 4627 The Unsolvable Problem
- 2013多校联合3 G The Unsolvable Problem(hdu 4627)
- HDU 4027 The Unsolvable Problem
- HDU 4267 The Unsolvable Problem
- hdu 4627 The Unsolvable Problem【hdu2013多校3签到】
- HDU-4627 The Unsolvable Problem 简单数学
- HDU 4627 The Unsolvable Problem 杭电多校联赛第三场1009 数学题
- 2013 Multi-University Training Contest 3 (g) The Unsolvable Problem
- hdu 4627 The Unsolvable Problem(暴力)
- BUCT OJ 2264: The Unsolvable Problem
- The Unsolvable Problem
- hdu 4627 The Unsolvable Problem(暴力的搜索)