内存限制10000k,错看成了1000k,一边骂POJ不厚道一边千方百计缩略mem开支,耽误良久,RE良久。艹 素数筛选 + 素因子拆分 #include <pzjay_cpy> using pzjay:space std; const int sup =4300;//预留sup个位置,略大于oo范围内生成的实际素数个数 const int oo = 40000; bool isp[oo + 10]; int prime[sup]; int x; int ans[sup];//ans[i]表示第i个素数出现了几次 int CNT;//记录生成的素数个数 void split(int x)//拆分x的素因子 { memset(ans, 0, sizeof(ans)); for(int i = 0; i < CNT && x > 0; ++i) { while(0 == x % prime[i]) { x /= prime[i]; ++ans[i];//第i个素因子个数++ } } } int Pow(int n, int p) { int tp = 1; while(p > 1) { if(p & 1) tp *= n; n *= n; p >>= 1; } return tp * n; } void Generate() { memset(isp, 1, sizeof(isp)); isp[0] = isp[1] = 0; for(int i = 2; i <= (oo >> 1); ++i) if(isp[i]) for(int j = 2; i * j <= oo; ++j) isp[i * j] = false; int cnt = 0; for(int i = 2; i < oo; ++i) if(isp[i]) prime[cnt++] = i; CNT = cnt; } char str[sup]; int rec[sup]; int main() { int it; Generate(); while(gets(str)) { stringstream ss; if('0' == str[0]) return 0; x = 1; int cnt = 0; ss << str; while(ss >> it) { rec[cnt++] = it; ss.clear(); } for(int i = 0; i < cnt; i += 2) x *= Pow(rec[i], rec[i + 1]);//Pow(a, b) = a ^ b split(--x); for(int i = CNT - 1; i >= 0; --i) if(ans[i]) printf("%d %d ", prime[i], ans[i]); printf("/n"); } return 0; }