LightOJ1014 Ifter Party

Description
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 L piaju'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
4
10 0
13 2
300 98
1000 997
Sample Output
Case 1: 1 2 5 10
Case 2: 11
Case 3: 101 202
Case 4: impossible

求n - l 比l 大的约数,暴力即可。


#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
int s[1000005];
int main() {
    LL a,b;
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++){
        scanf("%lld%lld",&a,&b);
        LL n=a-b;
        if(2*b>a){
            printf("Case %d: impossible\n",i);
            continue;
        }
        LL m=sqrt(n+0.5);
        int cnt=0;
        int flag=0;
        for(int i=1;i<=m;i++){
            if(n%i==0){
                s[cnt++]=i;
                if(i>b||n/i>b){
                    flag=1;
                }
            }
        }
        if(!flag){
            printf("Case %d: impossible\n",i);
        }else{
            printf("Case %d:",i);
            for(int i=0;i<cnt;i++){
                if(s[i]>b){
                    printf(" %d",s[i]);
                }
            }
            if(n/s[cnt-1]==s[cnt-1]){
                cnt--;
            }
            for(int i=cnt-1;i>=0;i--){
                if(n/s[i]>b){
                    printf(" %d",n/s[i]);
                }
            }
            printf("\n");
        }
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值