1014 - Ifter Party
 

I have an Ifter party at the 5th day of Ramadan for the contestants. For this reason I have invited C contestants and arranged P piaju's (some kind of food, specially made for Ifter). Each contestant ate Q piaju's and Lpiaju's were left (L < Q).

Now you have to find the number of piaju's each contestant ate.

Input

Input starts with an integer T (≤ 325), denoting the number of test cases.

Each case contains two non-negative integers P and L (0 ≤ L < P < 231).

Output

For each case, print the case number and the number of possible integers in ascending order. If no such integer is found print 'impossible'.

Sample Input

Output for Sample Input

4

10 0

13 2

300 98

1000 997

Case 1: 1 2 5 10

Case 2: 11

Case 3: 101 202

Case 4: impossible

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(void)
{
int T, cas;
int p, l;
vector<int>vec;

scanf("%d", &T);

cas = 0;

while(T--)
{
cas++;
vec.clear();

scanf("%d%d", &p, &l);

int n = p - l;

int m =(int)sqrt(n);

for(int i = 1; i <= m; i++)
{
if(n % i == 0)
{
if(i > l)
vec.push_back(i);
if(i * i != n)
{
if(n / i > l)
vec.push_back(n / i);
}
}
}

sort(vec.begin(), vec.end());
printf("Case %d:", cas);

int mm = vec.size();
if(mm == 0)
printf(" impossible\n");

for(int i = 0; i < mm; i++)
printf(" %d", vec[i]);

printf("\n");
}
return 0;
}

c++容器<vector>文件名#include<vector>   定义vector<int>c;

        c.clear()         移除容器中所有数据。

c.empty()         判断容器是否为空。

c.erase(pos)        删除pos位置的数据

c.erase(beg,end) 删除[beg,end)区间的数据

c.front()         传回第一个数据。

c.insert(pos,elem)  在pos位置插入一个elem拷贝

c.pop_back()     删除最后一个数据。

c.push_back(elem) 在尾部加入一个数据。

c.resize(num)     重新设置该容器的大小

c.size()         回容器中实际数据的个数。

c.begin()           返回指向容器第一个元素的迭代器

c.end()             返回指向容器最后一个元素的迭代器

light oj 1014 - Ifter Party分解因子的更多相关文章

  1. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

  2. uva 993 Product of digits (贪心 + 分解因子)

      Product of digits  For a given non-negative integer number N , find the minimal natural Q such tha ...

  3. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  4. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  5. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  6. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  7. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

  8. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

  9. Jan's light oj 01--二分搜索篇

    碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计 ...

随机推荐

  1. BigDecimal的加减乘除,比较,小数保留

    关于BigDecimal的一些常用基本操作记录 1        BigDecimal b1 = new BigDecimal("1.124"); 2        BigDeci ...

  2. Mysql连接出现时区问题

    错误提示: The server time zone value '¥x¥_¼Ð·Ç®É¶¡' is unrecognized or represents more than one time zon ...

  3. Callable接口用法

    注意点:FutureTask是Runnable的实现类,它的构造器可以传Callable接口的实现类. 例子如下: class MyThread implements Callable<Inte ...

  4. svn和 android adt的 eclipse插件更新地址

    下边这两个插件的更新地址是每次安装android开发环境时都能用到的,为了方便在这里记录一下. android adt: http://dl-ssl.google.com/android/eclips ...

  5. [bzoj1375] [Baltic2002] Bicriterial routing 双调路径

    Description 如今的道路收费发展很快.道路的密度越来越大,因此选择最佳路径是很现实的问题.城市的道路是双向的,每条道路有固定的旅行时间以及需要支付的费用. 路径是连续经过的道路组成的.总时间 ...

  6. 深入学习MySQL 02 日志系统:bin log,redo log,undo log

    上一篇文章中,我们了解了一条查询语句的执行过程,按理说这篇应该讲一条更新语句的执行过程,但这个过程比较复杂,涉及到了好几个日志与事物,所以先梳理一下3个重要的日志,bin log(归档日志).redo ...

  7. .net core 不是开源的么 作为菜 不能贡献源码 只有 欣赏额

    step one 去download一份 与前辈在一起

  8. Creating Custom Helper Methods 创建自定义辅助器方法----辅助器方法 ------ 精通ASP.NET MVC 5

    创建内联的辅助器方法 和 拓展方法 好像类似的功能. 不过写在前台更直观

  9. 基于快排思想的第(前)k大(小)

    算法思路就是根据快排的partition,先随机选择一个分隔元素(或a[0]),将数组分为[小于a[p]的元素] a[p] [大于a[p]的元素],如果这时候n-p+1等于k的话,a[p]就是所求的第 ...

  10. 【译】Serilog 配置基础知识

    Serilog 使用简单的C# API来配置日志记录.当外部配置需要时,可以使用Serilog.Settings.AppSettings包(.NET 框架)或Serilog.Settings.Conf ...