質數
bool isprime[32769];
int prime[32769];
typedef unsigned int ui;
int main(int argc, char const* argv[])
{
int m = 0;
for(int i = 2;i <= 32768;i++ ){
if(!isprime[i]){
prime[m++] = i;
for(int j = i*i;j <= 32768;j = j+i)
isprime[j] = true;
}
}
string line;
while(getline(cin,line) && line[0] != '0'){
int x,p;
istringstream stream(line);
int sum = 1;
while(stream>>x>>p){
sum = sum*pow(x,p);
}
sum--;
vector<int> ans;
for(int i = 0;prime[i]*prime[i] <= sum && i<m;i++){
if(sum%prime[i] == 0){
int count = 0;
ans.push_back(prime[i]);
while(sum%prime[i] == 0){
sum = sum/prime[i];
count++;
}
ans.push_back(count);
}
}
if(sum>1){
ans.push_back(sum);
ans.push_back(1);
}
int l = ans.size();
l--;
bool first = true;
for(int i =l;i >= 0;i = i-2){
if(!first)
printf(" %d %d",ans[i-1],ans[i]);
else {
printf("%d %d",ans[i-1],ans[i]);
first = false;
}
}
printf("\n");
}
return 0;
}