問題描述 求出區間[a,b]中所有整數的質因數分解。 輸入格式 輸入兩個整數a,b。 輸出格式 每行輸出一個數的分解,形如k=a1*a2*a3...(a1<=a2<=a3...,k也是從小到大的)(具體可看樣例) 樣例輸入 3 10 樣例輸出 3=3 4=2*2 5=5 6=2*3 7=7 8=2*2*2 9=3*3 10=2*5 提示 先篩出所有素數,然後再分解。 數據規模和約定 2<=a<=b<=10000
#include<iostream>
using
namespace
std;
int
main(){
int
a,b,k;
cin>>k>>b;
for
(;k <= b;k++){
a = k;
int
i = 2;
bool
t =
true
;
cout<<k<<
"="
;
while
(a - 1){
while
(a % i == 0){
if
(t){
t =
false
;
cout<<i;
}
else
cout<<
"+"
<<i;
a/=i;
}
i++;
}
cout<<endl;
}
return
0;
}