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: }

转载于:https://www.cnblogs.com/wuhenqs/p/3227030.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值