B - Ifter Party LightOJ - 1014

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


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define lowbit(x) (x&(-x))
using namespace std;

typedef unsigned long long ll;

const int maxn=1e6+10;
int ans[maxn];
/*
n^(1/2) 的复杂度,愣是让我当成了n的复杂度,感觉很难受
1e5的复杂度,感觉还是可以的
*/

int main(){
    int T,kase=1;
    scanf("%d",&T);
    while(T--){
        int p,l;
        scanf("%d %d",&p,&l);
        int m=p-l;
        int tmp=(int)sqrt(m),cnt=0;
        for(int i=1;i<=tmp;i++){
            if(m%i==0){
                if(m/i==i&&i>l)
                    ans[cnt++]=i;
                else{
                    if(i>l)
                    ans[cnt++]=i;
                    if(m/i>l)
                    ans[cnt++]=m/i;
                }
            }
        }
        sort(ans,ans+cnt);
        printf("Case %d:",kase++);
        if(!cnt)printf(" impossible");
        else{
            for(int i=0;i<cnt;i++) printf(" %d",ans[i]);
        }
        printf("\n");
    }
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36424540/article/details/80229239