1014 - Ifter Party

1014 - Ifter Party
    PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB

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

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

 

SPECIAL THANKS: JANE ALAM JAN (DESCRIPTION, SOLUTION, DATASET)

求p-l大于l的因子

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <string>
#include <iostream>
#include <vector>
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxn=1<<30;
const int SIZE=1e5+10;
set<int>st;
void get_fac(int x,int l){
    st.clear();
    for(int i=1;i<=(int)sqrt((double)x);i++){
        if(x%i==0){
            if(i>l)st.insert(i);
            if(x/i>l)st.insert(x/i);
        }
    }
}
int main()
{
    int T,x;
    scanf("%d",&T);
    for(int cas=1;cas<=T;cas++){
        int p,l;
        scanf("%d%d",&p,&l);
        x=p-l;
        get_fac(x,l);
        printf("Case %d: ",cas);
        if(st.empty()){
            printf("impossible\n");
            continue;
        }
        set<int>::iterator it=st.begin();
        printf("%d",*it);
        for(it++;it!=st.end();it++){
            printf(" %d",*it);
        }
        printf("\n");
    }
    return 0;
}


你可能感兴趣的:(1014 - Ifter Party)