2 solutions

  • 0
    @ 2025-4-2 22:53:26
    #include <bits/stdc++.h>
    #define endl '\n'
    using namespace std;
    typedef pair<int, int> PII;
    using ll = long long;
    using ULL = unsigned long long;
    const int N = 1e7 + 5;
    
    int a, b, p[N], c[N]; //p[]记录因子,p[1]是最小因子,c[i]记录第i个因子的个数
    
    inline int divide(int n) {
        int m = 0;
        for (int i = 2; i <= n/i; i++) {
            if (n % i == 0) { // i是质数
                p[++m] = i,c[m] = 0;
                while (n % i == 0) n /= i,c[m]++; // 把n中重复的因子去掉,除掉所有i
            } 
        }
        if (n > 1) // n是质数
            p[++m] = n,c[m] = 1;
        return m; // 共m个因子
    }  
    
    inline void solve() {
        cin >> a >> b;
        for (int i = a; i <= b; i++){
            int m = divide(i);
            cout << i << "=";
            for(int j = 1; j <= m; j++){   //第j个因子
                for(int k = 1; k <= c[j]; k++){  //第j个因子的个数
                    cout << p[j];
                    if(k < c[j]) cout<<"*";
                }
                if(j < m) cout<<"*";
            }
            cout << endl;
        }
    }
    
    int main() {
        ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        int _ = 1;
        //int _; cin >> _;
        while (_--) solve();
        return 0;
    }
    

    Information

    ID
    1825
    Time
    1000ms
    Memory
    512MiB
    Difficulty
    7
    Tags
    # Submissions
    16
    Accepted
    9
    Uploaded By