LightOJ

来源:互联网 发布:ubuntu apt get 换源 编辑:程序博客网 时间:2024/06/09 20:50

直接枚举  n-m 的因子


#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<cmath>#include<set>#include<queue>#include<stack>#include<map>#define PI acos(-1.0)#define in freopen("in.txt", "r", stdin)#define out freopen("out.txt", "w", stdout)using namespace std;typedef long long ll;typedef unsigned long long ull;const int maxn = 1e6 + 7, maxd = 1e4 + 7, mod = 1e9 + 7;const ll INF = 0x7f7f7f7f;int n, m, a;stack<int> sk;int b[maxn];void solve() {    int t = sqrt(a);    int cnt = 0;    for(int i = 1; i <= t; ++i) {        if(a % i == 0) {            if(i > m) printf(" %d", i);            int tmp = a/i;            if(tmp != i && tmp > m) b[cnt++] = tmp;        }    }    //while(!sk.empty()) { printf(" %d", sk.top()); sk.pop(); }    for(int i = cnt-1; i >= 0; --i)        printf(" %d", b[i]);    puts("");}int main() {    int T;    scanf("%d", &T);    for(int ks = 1; ks <= T; ++ks) {        scanf("%d %d", &n, &m);        printf("Case %d:", ks);        a = n - m;        if(a <= m) puts(" impossible");        else solve();    }    return 0;}