#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <bitset>
#include <cmath>
#include <algorithm>
using namespace std;
bitset<32768> p;
vector<int> prime;
void calc(){
int tmp=sqrt(32768);
for(int i=2;i<32768;i++){
if(!p[i]){
prime.push_back(i);
if(i<=tmp)
for(int j=i*i;j<32768;j+=i)
p[j]=1;
}
}
}
int main(){
ios::sync_with_stdio(0);
calc();
while(true){
string s;
ws(cin);
getline(cin,s);
if(s.size()==1)
return 0;
stringstream ss(s);
int x,p,num=1;
while(ss>>x>>p){
num*=pow(x,p);
}
num--;
vector<int> a;
int j=(upper_bound(prime.begin(),prime.end(),num)-prime.begin())-1;
while(j>=0){
if(num%prime[j]==0){
a.push_back(prime[j]);
num/=prime[j];
}
else
j--;
}
for(int i=0;i<a.size();){
cout<<a[i]<<' ';
int c=1,tmp=a[i];
i++;
while(i<a.size()&&a[i]==tmp)
c++,i++;
cout<<c;
if(i<a.size())
cout<<' ';
}
cout<<endl;
}
}
#include <vector>
#include <string>
#include <sstream>
#include <bitset>
#include <cmath>
#include <algorithm>
using namespace std;
bitset<32768> p;
vector<int> prime;
void calc(){
int tmp=sqrt(32768);
for(int i=2;i<32768;i++){
if(!p[i]){
prime.push_back(i);
if(i<=tmp)
for(int j=i*i;j<32768;j+=i)
p[j]=1;
}
}
}
int main(){
ios::sync_with_stdio(0);
calc();
while(true){
string s;
ws(cin);
getline(cin,s);
if(s.size()==1)
return 0;
stringstream ss(s);
int x,p,num=1;
while(ss>>x>>p){
num*=pow(x,p);
}
num--;
vector<int> a;
int j=(upper_bound(prime.begin(),prime.end(),num)-prime.begin())-1;
while(j>=0){
if(num%prime[j]==0){
a.push_back(prime[j]);
num/=prime[j];
}
else
j--;
}
for(int i=0;i<a.size();){
cout<<a[i]<<' ';
int c=1,tmp=a[i];
i++;
while(i<a.size()&&a[i]==tmp)
c++,i++;
cout<<c;
if(i<a.size())
cout<<' ';
}
cout<<endl;
}
}
Comments
Post a Comment