USACO sec1.5 Superprime Rib

没打表。

/*

PROG : sprime

LANG : C++

*/

# include <stdio.h>



/*******************************/

char isp(int x)

{

    int i;

    if (x%2 == 0) return x == 2;

    if (x%3 == 0) return x == 3;

    if (x%5 == 0) return x == 5;

    for (i = 7; i*i < x; i+= 2)

        if (x%i == 0) return 0;

    return 1;

}



void g(int x, int rem)

{

    int i;

    if (rem == 0) printf("%d\n", x);

    else for (i = 1; i <= 9; i += 2)

        if (isp(x*10+i)) g(x*10+i, rem-1);

}

/*******************************/



void solve(void)

{

    int i, n;

    scanf("%d", &n);

    for (i = 2; i <= 7; ++i) if (isp(i))

        g(i, n-1);

}



int main()

{

    freopen("sprime.in", "r", stdin);

    freopen("sprime.out", "w", stdout);

    

    solve();

    

    fclose(stdin);

    fclose(stdout);

        

    return 0;

}

 

你可能感兴趣的:(USACO)