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. dp-划分数 (递推)

    问题描述 : 有 n 个无区别的物品 , 将他们分成 不超过 m 堆, 问有多少种分法 ? 例如 : n = 4 , m = 3 , 则总共有的分法是 1 + 2 +1 , 0 + 1 + 3 , 0 ...

  2. background-position和position

    1.background-position:表示背景定位的属性.描述属性值时,有两种方式:一是像素描述:而是单位描述. (1)像素描述: 格式如下: background-position:向右偏移量 ...

  3. Webpack实战(六):如何优雅地运用样式CSS预处理

    上一篇文章中,我主要分享了<Webpack如何分离样式文件>CSS 预处理器是一个能让你通过预处理器自己独有的语法来生成CSS的程序,css预处理指的是在开发中我们经常会使用一些样式预编译 ...

  4. python 线程池实用总结

    线程池的两张方法 submit 和map from concurrent.futures import ThreadPoolExecutor import time # def sayhello(a) ...

  5. http请求头中的content-type属性

    在HTTP请求中,我们每天都在使用Content-Type来指定不同格式的请求信息,但是却很少有人去全面了解Content-Type中允许的值有多少,因此这里来了解一下Content-Type的可用值 ...

  6. centOS7.1安装nginx与可能遇见的问题

    一,安装nginx(系统:CentOS7.1) 1.Nginx下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz [root@linux src]# c ...

  7. mybatis增强工具MyBatis-plus

    如果你正在用mybatis,那MyBatis-plus你不能错过,配合使用可极大简化开发.提高效率! 简介 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis ...

  8. 基于python的感知机

    一. 1.感知机可以描述为一个线性方程,用python的伪代码可表示为: sum(weight_i * x_i) + bias -> activation #activation表示激活函数,x ...

  9. HttpApplication IHttpAsyncHandler, IHttpHandler, IComponent, IDisposable ps url System.Web.dll

    // 摘要:     //     定义 ASP.NET 应用程序中的所有应用程序对象共有的方法.属性和事件.此类是用户在 Global.asax 文件中所定义的应用程序的基类.     [Toolb ...

  10. 使用luabind绑定box2d的lua接口

    最近在使用luabind绑定box2d的lua接口,发现不少问题.写在这里与大家分享. 1. body,fixture,joint的userdata.box2d的userdata的数据类型是void* ...