#include #include int hash(int N) { int work = N; int hash = 0; int base = 10; while (1) { while (work != 0) { hash += (work % base); work /= base; } if (hash >= base) { work = hash; hash = 0; } else { break; } } return hash; } int Pr_begin = 0; int Pr_end = 0; int *Pr = 0; int pr_gen(int K, int N) { int i, j; char *chk = (char*)malloc(sizeof(char)*(N+1)); for (i=0; i<=N; i++) chk[i] = 1; chk[0] = 0; chk[1] = 0; for (i=2; i<=N; i++) { if (chk[i] == 1) { for (j=i*2; j<=N; j+=i) chk[j] = 0; Pr_end++; } } Pr = (int*)malloc(sizeof(int)*Pr_end); Pr_end = 0; for (i=0; i<=N; i++) { if (chk[i] == 1) { Pr[Pr_end] = i; Pr_end++; } } free(chk); chk = 0; if (K <= Pr[0]) { Pr_begin = 0; } else { for (i=0; i