判断到根号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. Code for the Homework1 改进

    #include <iostream> #include <vector> #include "shape.h" //using namespace std ...

  2. 对日期和时间的处理 NSCalendar

    代码较老,供参考 NSCalendar用于处理时间相关问题.比如比较时间前后.计算日期所的周别等. 1. 创建或初始化可用以下方法 + (id)currentCalendar; 取得当前用户的逻辑日历 ...

  3. bnuoj 20838 Item-Based Recommendation (模拟)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=20838 [题意]: 有点长,略. [code]: #include <iostream> ...

  4. poj 1679 The Unique MST(唯一的最小生成树)

    http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  5. @Entity设置实体lazy = false

    问题描述 在通过Hibernate查询Bean信息时报以下异常信息: org.hibernate.LazyInitializationException: could not initialize p ...

  6. zoj 3365

    题意 给你一个序列  改变尽可能少的数使其成为公差为一 递增的等差数列 可以将给你的序列减去一个等差数列 即num[i] -= i,若得到的数全部相等, 则说明给你的序列本身就满足条件  则只要寻求n ...

  7. uva 825

    这个......小学生就会的  坑在输入输出了  两个数之间可能不止一个空格....wa了好几遍啊 #include <cstdio> #include <cstring> # ...

  8. Android名词解释

    System Bars.Status Bar.Navigation Bar System Bars-->the Status bars and Navigation bars.

  9. [Firefly引擎][学习笔记一][已完结]带用户验证的聊天室

    原地址:http://bbs.9miao.com/thread-44571-1-1.html 前言:早在群里看到大鸡蛋分享他们团队的Firefly引擎,但一直没有时间去仔细看看,恰好最近需要开发一个棋 ...

  10. 认识FiddlerScript

    FiddlerScript 是Fiddler 的一项非常强大的功能,它允许你增强Fiddler UI,添加新的特性,修改请求与响应内容等等... 1.编写FiddlerScript FiddlerSc ...