判断到根号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. 【BZOJ 2242】[SDOI2011]计算器

    Description 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给 ...

  2. iOS的layoutSubviews和drawRect方法何时调用

    layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubviews.2.addSubview会触发layoutSubviews.3.设置view的Frame会触 ...

  3. Myeclipse 2013 professional 破解,下载

    昨天重装了系统,今天重新搭建开发环境,就顺便把Myeclipse升级到了2013,点击下载Myeclipse2013.惯例,需要破解Myeclipse2013,不过我发现我之前的破解Myeclipse ...

  4. What the hell is Rotate?

  5. stl map高效遍历删除的方法

    for(:iter!=mapStudent.end():) {      if((iter->second)>=aa)      {          //满足删除条件,删除当前结点,并指 ...

  6. Ubuntu环境下手动配置Java环境

    /×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...

  7. jquery中事件重复绑定以及解绑问题

    一般的情况下,对于这种情况,我们常规的思路是,先解绑,再绑定,如下: $(selector).unbind('click').bind('click',function(){....}); 当这样会有 ...

  8. laravel的解决方案

    对form表单批量去掉前后空格trim: $request->merge(array_map('trim', $request->all())); 或 Input::merge(array ...

  9. POJ2965——The Pilots Brothers' refrigerator

    The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: following the stripy el ...

  10. Java命令行实用工具jps和jstat

    在Linux或其他UNIX和类UNIX环境下,ps命令想必大家都不陌生,我相信也有不少同学写过 ps aux | grep java | grep -v grep | awk '{print $2}' ...