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)。

(为什么我每次看到题目都想去暴力。。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代码:

   1: #include <stdio.h>
   2: #include <math.h>
   3: #include <iostream>
   4: #include <cstdarg>
   5: #include <algorithm>
   6: #include <string.h>
   7: #include <stdlib.h>
   8: #include <string>
   9: #include <list>
  10: #include <vector>
  11: #include <map>
  12: #define LL __int64
  13: #define M(a) memset(a, 0, sizeof(a))
  14: using namespace std;
  15:  
  16: void Clean(int count, ...)
  17: {
  18:     va_list arg_ptr;
  19:     va_start (arg_ptr, count);
  20:     for (int i = 0; i < count; i++)
  21:         M(va_arg(arg_ptr, int*));
  22:     va_end(arg_ptr);
  23: }
  24:  
  25: int main()
  26: {
  27:     LL T;
  28:     cin >> T;
  29:     while (T--)
  30:     {
  31:         LL n;
  32:         cin >> n;
  33:         LL i = n / 2;
  34:         if (n == 2) cout << 1 << endl;
  35:         else if (n % 2) cout << (i * (i + 1)) << endl;
  36:         else if (i % 2) cout << ((i - 2) * (i + 2)) << endl;
  37:         else  cout << ((i - 1) * (i + 1)) << endl;
  38:     }
  39:     return 0;
  40: }
posted @ 2013-07-31 09:27  ~無痕~  阅读(309)  评论(0编辑  收藏  举报