light oj 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分解因子的更多相关文章
- Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩
题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...
- uva 993 Product of digits (贪心 + 分解因子)
Product of digits For a given non-negative integer number N , find the minimal natural Q such tha ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
- Jan's light oj 01--二分搜索篇
碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计 ...
随机推荐
- dp-(LCS 基因匹配)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19885 Accepted: ...
- poj 2689 区间素数筛
The branch of mathematics called number theory is about properties of numbers. One of the areas that ...
- Docker + node(koa) + nginx + mysql 线上环境部署
在上一篇 Docker + node(koa) + nginx + mysql 开发环境搭建,我们进行了本地开发环境搭建 现在我们就来开始线上环境部署 如果本地环境搭建没有什么问题,那么线上部署的配置 ...
- 简单理解设计模式——享元模式-线程池-任务(tesk)
前面在写到多线程的文章的时候,一直想写一篇关于线程池等一系列的文章,做一下记录,本篇博客记录一下设计模式中享元模式的设计思想,以及使用享元模式的实现案例——线程池,以及线程池的简化版——任务(tesk ...
- linux下redis的部署
https://www.cnblogs.com/wangchunniu1314/p/6339416.html https://www.linuxidc.com/Linux/2017-09/146894 ...
- ios---二维码的扫描
二维码扫描 使用ios的AVFoundation框架实现二维码扫描 第一步:设置相机访问权限:在Info.plist添加Privacy - Camera Usage Description权限 第二步 ...
- php--->php 缓冲区 buffer 原理
php 缓冲区 buffer 原理 1.缓冲流程 从php脚本echo(print.print_r...)内容之后,是如何显示给用户的呢,下面看看流程 echo.print => php out ...
- Docker扩展内容之容器环境变量
介绍 docker容器设置环境变量除了可以在容器层面的变量文件中加载也可以在容器运行之初进行预加载环境变量,下面介绍在Dockerfile中编写环境变量的方式 ENV TZ=Asia/Shanghai ...
- JDK Proxy和CGLIB Proxy
动态代理在Java中有着广泛的应用,比如Spring AOP,Hibernate数据查询.测试框架的后端mock.RPC,Java注解对象获取等.静态代理的代理关系在编译时就确定了,而动态代理的代理关 ...
- 尝试用 Python 写了个病毒传播模拟程序
病毒扩散仿真程序,用 python 也可以. 概述 事情是这样的,B 站 UP 主 @ele 实验室,写了一个简单的疫情传播仿真程序,告诉大家在家待着的重要性,视频相信大家都看过了,并且 UP 主也放 ...