每个数都可以表示成若干个素数的相乘形式,现在给你一个数num的质数相乘的形式,请输出num-1的质数相乘形式。 例如 样例二:(5^1)*(2^1)=num=10 ,所以num-1=9=3^2 输出的质数pi 按降序输出
Input
The input consists of lines (at least one) each of which except the last contains prime base representation of just one positive integer greater than 2 and less or equal 32767. All numbers in the line are separated by one space. The last line contains number 0.
Output
The output contains one line for each but the last line of the input. If x is a positive integer contained in a line of the input, the line in the output will contain x - 1 in prime base representation. All numbers in the line are separated by one space. There is no line in the output corresponding to the last ``null'' line of the input.
Sample Input
17 1 5 1 2 1 509 1 59 1 0
Sample Output
2 4 3 2 13 1 11 1 7 1 5 1 3 1 2 1
我把幂乘写成了乘 自闭两小时 开始怀疑我的欧拉筛板子
见代码 其实是一道水题。。。唯一分解 + 欧拉筛
#include<iostream>
#include<cmath>
#include<vector>
#include<stdio.h>
#define ll long long
const ll maxnn = 1e5 + 5;
const ll maxn = 1e5;
using namespace std;
ll sum = 0;
ll tot = 0;
ll p[maxnn], isp[maxnn];
ll ans1[maxn], ans2[maxn];
void init(){
for(ll i = 2; i <= maxn; i++){
if(!isp[i]){
isp[i] = i;
p[++tot] = i;
}
for(ll j = 1; j <= tot; j++){
if(p[j] > isp[i] || p[j] * i > maxn)
break;
isp[p[j] * i] = p[j];
}
}
}
void solve(){
sum--;
int t = 0;
for(ll i = 1; i <= tot && p[i] * p[i] <= sum; i++){
if(sum % p[i] == 0){
ll cnt = 0;
while(sum % p[i] == 0){
cnt++;
sum /= p[i];
}
ans1[++t] = p[i];
ans2[t] = cnt;
}
}
if(sum > 1){
ans1[++t] = sum;
ans2[t] = 1;
}
for(int i = t; i >= 1; i--)
cout << ans1[i] << " " << ans2[i] << " ";
cout << endl;
}
int main(){
init();
while(1){
ll a, b;
sum = 1;
cin >> a;
if(!a)
return 0;
cin >> b;
sum *= pow(a, b);
while(getchar() != '\n'){
cin >> a;
cin >> b;
sum *= pow(a, b);
}
solve();
}
}