给你一个数 n ( 2 <= n <= 109 ),现在需要你找到一对数a, b (a + b = n),并且使得LCM(a, b)尽可能的大,然后输出最大的 LCM(a, b)。
(为什么我每次看到题目都想去暴力。。Orz 题外话)
这道题先对 n = 2 的情况进行判断,从输出可以知道 n = 2 的时候 ans = 1。接着对 n 进行分情况讨论。当 n = 2k + 1 的时候,ans = k * (k + 1)。
当 n = 2k 的时候:
当 k 为偶数的时候 ans = (k + 1) * (k - 1)
当 k 为奇数的时候 ans = (k + 2) * (k - 2)
P.S : 杭电给的解题报告写反了。。Orz
这道题目的定位是签到题,就不多说了。
附AC代码:
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <cstdarg>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <list>
#include <vector>
#include <map>
#define LL __int64
sizeof(a))
namespace std;
15:
int count, ...)
17: {
18: va_list arg_ptr;
19: va_start (arg_ptr, count);
int i = 0; i < count; i++)
int*));
22: va_end(arg_ptr);
23: }
24:
int main()
26: {
27: LL T;
28: cin >> T;
while (T--)
30: {
31: LL n;
32: cin >> n;
33: LL i = n / 2;
if (n == 2) cout << 1 << endl;
if (n % 2) cout << (i * (i + 1)) << endl;
if (i % 2) cout << ((i - 2) * (i + 2)) << endl;
else cout << ((i - 1) * (i + 1)) << endl;
38: }
return 0;
40: }