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.不好直接求解的一类计 ...
随机推荐
- Mysql-SQL优化-子查询替代LEFT JOIN
表A:批次信息表, 表B:实际批次明细表, Mysql版本:5.6.36 两表之间的数据体量差异:表B是表A的10000倍. 经过结转,表B通常保留 1千5百万数据.表A就是1千多条数据. 计算近24 ...
- $.fn.serializeObject对为disabled属性的失效
问题现象: 在查生产tomcat下的localhost日志时,发现今天的记录有不少次都报org.apache.ibatis.exceptions.TooManyResultsException: Ex ...
- python-review01
# 1.使用while循环输出 1 2 3 4 5 6 8 9 10 count = 0 while count < 10: count += 1 if count == 7: continue ...
- asp.net生成店铺推广二维码,二维码中间加logo(源码)
二维条码比一维条码记载数据量更多,二维码条码是一种高密度.高信息含量的便携式数据文件,是实现证件及卡片等大容量.高可靠性信息自动存储.携带并可用机器自动识读的理想手段.而且可以记载更复杂的数据,比如图 ...
- [DP][SA][可持久化线段树]黑红兔
源自 xyz32768 菜鸡的 FJ 省冬令营模拟赛题 原题 CF1063F Statement 给定一个长度为 \(n\) 的字符串 \(s\),仅包含小写英文字母 要从中从左往右选出若干段不相交的 ...
- RainbowPlan-Alpha版本发布2
博客介绍 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/ 这个作业要求在哪里 https:// ...
- robotframework从列表中循环读取数据,传入关键字执行
场景预设:从列表内读取手机号,自动化执行微信加好友,直至选择完所有数据后,脚本停止执行 1.建一个备选数据表,表内列待添加的手机号数据 2.脚本的主要流程新加好友-输入手机号-添加好友-判断好友是否存 ...
- C语言寒假大作战02
2.2.1 寒假大作战 问题 回答 这个作业属于哪个课程 2019软件四班C语言寒假作业大作战 这个作业要求在哪里 作业要求 我在这个课程的目标是 用switch完成一个menu基本框架 这个作业在那 ...
- redis端口6379的由来
有一个技巧,Redis端口号6379,是手机键盘上的MERZ.
- Object-c的字符串处理常用方法
Object-c的字符串处理常用方法 #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { ...