判断到根号n即可,另外使用dfs输出,不需要另开数组再排序。


#include<cmath>

#include<cstdio>

int P, L, len, cnt;

void dfs(int dep){

    if(dep > len) return;

    if(dep > L){

        if(P % dep == 0){

            if(cnt == 1) printf("%d", dep), cnt = 2;

            else printf(" %d", dep);

            dfs(dep+1);

            if(P/dep != dep && P/dep > L) {

                if(cnt == 1) printf(" %d", P/dep), cnt = 2;

                else printf(" %d", P/dep);

            }

        }else dfs(dep+1);

    }else {

        dfs(dep+1);

        if(P % dep == 0 && P/dep > L) {

            if(cnt == 1) printf("%d", P/dep), cnt = 2;

            else printf(" %d", P/dep);

        }

    }

}

int main(){

    int t, CASE(0);

    scanf("%d", &t);

    while(t--){

        scanf("%d%d", &P, &L);

        if(L >= P - L) printf("Case %d: impossible\n", ++CASE);

        else {

            P -= L;

            len = sqrt(P);

            printf("Case %d: ", ++CASE);

            cnt = 1;

            dfs(1);

            printf("\n");

        }

    }

lightoj 1014的更多相关文章

  1. Lightoj 1014 - Ifter Party

    I have an Ifter party at the 5th day of Ramadan for the contestants. For this reason I have invited  ...

  2. Ifter Party LightOJ - 1014(水题)

    题意:有C个人,给P个食物,每人吃Q个,剩L个.然后给你P和L(Q>L),让你求Q的可能情况,如果有多种可能,从小到大输出:如果不存在,输出impossible 就是求写出公式 遍历c求P-L的 ...

  3. LightOJ 1236 - Pairs Forming LCM(素因子分解)

    B - Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  4. LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS     Memor ...

  5. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  6. Pairs Forming LCM (LightOJ - 1236)【简单数论】【质因数分解】【算术基本定理】(未完成)

    Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of t ...

  7. 1014: [JSOI2008]火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Description 火星人最近研究了一种操作:求一个字串两个后缀 ...

  8. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  9. BZOJ 1014: [JSOI2008]火星人prefix [splay 二分+hash] 【未完】

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6243  Solved: 2007[Submit] ...

随机推荐

  1. 操作邮箱的类和文件的Md5【粘】

     MailMessage mailMsg = new MailMessage();//两个类,别混了,要引入System.Net这个Assembly             mailMsg.From ...

  2. c#无标题窗体点击任务栏图标正常最小化或还原

    FormBorderStyle等于System.Windows.Forms.FormBorderStyle.None的窗体,点击任务栏图标的时候,是不能象标准窗体那样最小化或还原的. protecte ...

  3. 解决Oracle ORA-00984: column not allowed here

    某列是字符列,结果忘记加单引号了 INSERT INTO prt_document_present (company_code, doc_no, seq_no, field_name, desc_ms ...

  4. Nagios3完整配置文档

    第一章:简单快速安装nagios 1.1 准备软件包 在做安装之前确认要对该机器拥有root权限. 确认你安装好的linux系统上已经安装如下软件包再继续. Apache GCC编译器 GD库与开发库 ...

  5. git 命令整理

    记录一些git 命令,以便自己以后查阅 基本命令   1.git add (保存工作区的变动到暂存区) git add . 和git add -A把整个工作区添加到暂存区 2.git commit ( ...

  6. eclipse运行hadoop程序报错:Connection refused: no further information

    eclipse运行hadoop程序报错:Connection refused: no further information log4j:WARN No appenders could be foun ...

  7. spring的组成

    ① Spring Core:核心容器,BeanFactory提供了组件生命周期的管理,组件的创建,装配,销毁等功能 SpringContext:ApplicationContext,扩展核心容器,提供 ...

  8. Source Insight的应用技巧、宏功能

    目录 1 简介... 5 2 搭建我们的SI环境... 5 2.1 搭建步骤... 5 2.2 说明... 6 3 应用技巧... 6 3.1 初级应用技巧... 6 3.1.1 解决字体不等宽与对齐 ...

  9. AC题目简解-dp

    dp类:A - Bridging signals ZOJ 3627 POJ1631 HDU1950给出一个从1-n的数字排列,求最长上升子序列长度.直接说解法吧.新开一个数组d,d[i]表示的是能构成 ...

  10. Git教程之删除文件(8)

    在Git中,删除也是一个修改操作,我们实战一下,先添加一个新文件test.txt到Git并且提交: