首页 > ACM题库 > HDU-杭电 > HDU 4627-The Unsolvable Problem[解题报告]HOJ
2015
09-17

HDU 4627-The Unsolvable Problem[解题报告]HOJ

The Unsolvable Problem

问题描述 :

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.

输入:

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.

输出:

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.

样例输入:

3
2
3
4

样例输出:

1
2
3

这场比赛最简单的一个题,题意大致是说给你一个n,要求你求出满足a+b=n,并且a、b的最小公倍数最大

思路:

要使得2个数的最小公倍数最大,要使得其尽量的接近

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
	__int64 n;
	scanf("%I64d",&n);
	if(n==2)
	{
	    printf("1\n");
	    continue;
	}
	if(n&1)
	    printf("%I64d\n",(n/2)*(n/2+1));
	else
	{
	    n/=2;
	    if(n&1)
		printf("%I64d\n",(n-2)*(n+2));
	    else
		printf("%I64d\n",(n-1)*(n+1));
	}

    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/z309241990/article/details/9970625