1014 - Ifter Party

题目大意:

节日到了,家里办party,邀请了c个小伙伴来做客,家里有P个每个小伙伴吃掉Q个派,剩下L个,输入P、L,要求你输出所有的可能的Q的值;

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

P and L (0 ≤ L < P < 231).


解题思路:

假设n=P-L,那么这道题目的意思就是要你求出所有的n的因数啊!其实直接暴力枚举就到了,因为时间复杂度为n

上个代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#define __int64 long long
using namespace std;
int cas;
 int P,L,n;
void Ans ()
{
    set<int> s;//用set()既不用考虑重复,又不用考虑排序,多么美好的一个东西啊。

    for (__int64 i=1;i*i<=n;i++)
        if (n%i == 0)
        {
            if (i>L)
                s.insert(i);
            if (n/i > L)
                s.insert(n/i);
        }
		printf("Case %d: ",cas);
		if (s.empty())
			printf("impossible\n");
		else
		{
			set<int>::iterator it,it2;
			it2=s.begin();
			it2++;
			for (it=s.begin();it2!=s.end();it++,it2++)
				printf("%d ",*it);
			printf("%d",*it);
			printf("\n");
		}
   }
int main()
{
	int T;
	scanf("%d",&T);
	for (cas=1;cas<=T;cas++)
	{
	    scanf("%d%d",&P,&L);
	     n=P-L;
		Ans ();
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值