Description
求出区间[a,b]中所有整数的质因数分解。
Input
输入两个整数a,b。
Output
每行输出一个数的分解,形如k=a1a2a3…(a1<=a2<=a3…,k也是从小到大的)(具体可看样例)
Sample Input 1
3 10
Sample Output 1
3=3
4=22
5=5
6=23
7=7
8=222
9=33
10=25
#include <iostream>
using namespace std;
bool Is_prime(int x){
if(x==2||x==3) return true;
else{
for(int i=2;i<x;i++){
if(x%i==0) return false;
}
return true;
}
}
void division(int x){
int i=2;
while(!Is_prime(x)){
if(Is_prime(i)){
if(x%i==0){
cout<<i<<"*";
x=x/i;
}
else
i++;}
else
i++;
}
cout<<x;
}
int main(){
int a,b;
cin>>a>>b;
for(int i=a;i<=b;i++){
if(Is_prime(i)==true)
cout<<i<<"="<<i;
else{
cout<<i<<"=";
division(i);
}
cout<<endl;
}
}