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.不好直接求解的一类计 ...
随机推荐
- java学生管理系统(增、删、改、查功能)
package mm; import java.util.Scanner;import java.util.ArrayList; class Student1 { private String stu ...
- Activiti定时任务
Activiti定时任务 作者:Jesai 傻逼一样的去坚持,就会有牛逼的结果 情景: 某公司有一个OA系统,审批环节是经理.有一天,经理出差了,然后下面突然有一份决定公司某个重大项目是否能顺利中标的 ...
- Linux安装python和更新pip
一.安装python 1.安装依赖包 1).安装gcc 通过gcc --version 查看,若没有则安装gcc yum -y install gcc 2).安装其他依赖包 yum -y instal ...
- Spring加载早期获取BasePackage
public class GetBasePackage { private Class<? extends Annotation> annotation; public GetBasePa ...
- selenium2-Python环境搭建
一.什么是selenium? selenium主要用于web应用的自动化测试,但并不局限于此,它还支持基于所有web的管理任务自动化,且开源免费,多浏览器支持(IE,Mozilla Firefox,S ...
- Quantitative Trading with R(一):两个简单的策略
下面是两个使用R中的Quantstrat包进行策略构建的例子,都是对600550.ss.600192.ss.600152.ss.600644.ss.600885.ss.600151.ss六只股票进行投 ...
- ios---设置UITabBarController的字体颜色和大小
+(void)load{ NSMutableDictionary *attr3=[NSMutableDictionary dictionary]; attr3[NSForegroundColorAtt ...
- 解决warning: #181-D: argument is incompatible with corresponding format string conversion警告
uint8_t NetRSSI=0;uint8_t NetBer=0;uint8_t failtime=0; sscanf(&USART_RX_BUF[0],"%*s%u,%u&qu ...
- 缓存 ehcache
只是用于自己记录,防止日后忘记,回看所用 第一步:配置ehcahe 缓存 <?xml version="1.0" encoding="UTF-8"?> ...
- .net core3.1 web api中使用newtonsoft替换掉默认的json序列化组件
在微软的文档中,有着较为详细的替换教程 https://docs.microsoft.com/zh-cn/aspnet/core/web-api/advanced/formatting?view=as ...