基础练习 分解质因数

基础练习 分解质因数
时间限制:1.0s 内存限制:512.0MB
问题描述

  求出区间[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
using namespace std;

int main()
{
    int a,b,c[10003]={0,2},index=1;
    cin>>a>>b;
    for(int i=3;i<=b;i++){
            bool tlag=true;
        for(int j=1;c[j]!=0;j++){
            if(!(i%c[j])){
                tlag=false;
                continue;
            }
        }
        if(tlag) c[++index]=i;
    }
    for(int i=a;i<=b;i++){
        int temp = i;
        cout<"=";
        for(int j=1;temp!=1;){
            if(!(temp%c[j])){
                if(temp/c[j]!=1) cout<"*";
                else cout<else j++;
        }
    }
    return 0;
}

你可能感兴趣的:(内存)