2013-07-30 20:35 388人阅读 评论(0) 收藏 举报

http://acm.hdu.edu.cn/showproblem.php?pid=4627

The Unsolvable Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 230    Accepted Submission(s): 136

Problem Description
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.
 
Input
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.
 
Output
For each test cases,print the maximum [a,b] in a line.
标准签到题,先特判n==2的情况,否则若n为奇数,则答案显然是n/2 和 n/2+1,若n为偶数设n=2*k,若k为偶数,则答案为k-1,k+1,否则答案为k-2,k+2。
    1. #include <iostream>
    2. #include <string.h>
    3. #include <stdio.h>
    4. #include <algorithm>
    5. #define ll long long
    6. using namespace std;
    7. int main()
    8. {
    9. //freopen("dd.txt","r",stdin);
    10. ll n,ncase;
    11. cin>>ncase;
    12. while(ncase--)
    13. {
    14. cin>>n;
    15. if(n==2)
    16. cout<<1<<endl;
    17. else
    18. {
    19. if(n%2)
    20. cout<<(n/2)*(n-n/2)<<endl;
    21. else
    22. {
    23. if((n/2)%2==0)
    24. cout<<(n/2-1)*(n/2+1)<<endl;
    25. else
    26. cout<<(n/2-2)*(n/2+2)<<endl;
    27. }
    28. }
    29. }
    30. return 0;
    31. }
    32. 一开始用暴力,唉,挂了,但是为什么是这样呢,想了半天终于明白了。

2013多校联合3 G The Unsolvable Problem(hdu 4627)的更多相关文章

  1. 2013 多校联合 F Magic Ball Game (hdu 4605)

    http://acm.hdu.edu.cn/showproblem.php?pid=4605 Magic Ball Game Time Limit: 10000/5000 MS (Java/Other ...

  2. 2013多校联合2 I Warm up 2(hdu 4619)

    Warm up 2 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total ...

  3. 2013 多校联合2 D Vases and Flowers (hdu 4614)

    Vases and Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others ...

  4. 2013 多校联合 2 A Balls Rearrangement (hdu 4611)

    Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  5. Contest1585 - 2018-2019赛季多校联合新生训练赛第一场(部分题解)

    Contest1585 - 2018-2019赛季多校联合新生训练赛第一场 C 10187 查找特定的合数 D 10188 传话游戏 H 10192 扫雷游戏 C 传送门 题干: 题目描述 自然数中除 ...

  6. HDU 4690 EBCDIC (2013多校 1005题 胡搞题)

    EBCDIC Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Su ...

  7. HDU 4685 Prince and Princess (2013多校8 1010题 二分匹配+强连通)

    Prince and Princess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  8. HDU 4678 Mine (2013多校8 1003题 博弈)

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  9. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

随机推荐

  1. mysql 内存占用过多的解决方法

    以下是5.6默认的设置performance_schema_max_table_instances 12500table_definition_cache 1400table_open_cache 2 ...

  2. scala-- 内建控制结构

    内建控制结构 ​ scala 内建的控制结构很少,只有 if while for try match 和函数调用 几种. 因为scala 从语法层面支持函数字面量.几乎所有的scala控制结构都会产生 ...

  3. git cherry-pick基本使用

    git cherry-pick可以选择某一分支中的一个或几个commit来进行操作--commit 使用场景: 稳定版本分支1与开发版本分支2,不能直接把两个分支合并,否则会导致版本混乱,要将分支2中 ...

  4. 如何写一个自定义的js文件

    自定义一个Utils.js文件,在其中写js代码即可.如: (function(w){ function Utils(){} Utils.prototype.getChilds = function( ...

  5. JVM7、8详解及优化

    一.引言:永久代为什么被移出HotSpot JVM了? 详见:JEP 122: Remove the Permanent Generation 原因主要有两个: 1.由于Permanent Gener ...

  6. 工作流和过程自动化框架 Camunda BPM

    Camunda BPM 是一个灵活的工作流和过程自动化框架,它的核心是一个在Java虚拟机内部运行的原生BPMN 2.0流程引擎,因此它可以嵌入到任何Java应用程序或运行时容器中.Camunda B ...

  7. golang获取IP地址

    ip:=this.Ctx.Request.RemoteAddr ip=ip[0:strings.LastIndex(ip, ":")]

  8. ECMAScript5新特性之isFrozen、freeze

    对象被冻结后: 1 不能添加属性. 2 不能删除属性. 3 不能修改属性.(赋值) 4 不能修改属性描述符.(会抛异常) var fruit = { name : '苹果', desc : '红富士' ...

  9. jsoncpp在Windows和Linux下的安装

    Windows下: 参考这个网站,没什么问题,注意MTd这些选对就行了. http://www.cppblog.com/wanghaiguang/archive/2013/12/26/205020.h ...

  10. Mac 终端便利工具: 管理工具-Homebrew 和提示工具oh my zsh

    命令行提示工具 第一步: Homebrew - 安装与使用 https://blog.csdn.net/sir_coding/article/details/77509602 Homebrew安装问题 ...